JavaEE(1) - Weblogic 服务器管理的数据源

时间:2023-01-11 01:02:24

JBoss下载:

http://jbossas.jboss.org/downloads

http://www.cnblogs.com/xw-cnblogs/articles/2439969.html

WebLogic下载:

http://www.oracle.com/technetwork/middleware/weblogic/downloads/wls-main-097127.html

WebLogic安装:http://blog.csdn.net/shimiso/article/details/8120650

1. 启动

Method No.1: 开始-->Oracle Weblogic(Oracle Enterprise Package for Eclipse)-->User Projects-->base_domain-->Start Admin Server for Weblogic Server.

Method No.2: D:\domains\base_domain\startWeblogic.cmd

http://localhost:7001/console

2. 修改端口(如果必要)

base_domain-->Enviroment-->Servers-->AdminServer(admin)

3. 数据源配置

Method No.1: base_domain-->Services-->Data Sources.

Method No.2: D:\domains\base_domain\config\jdbc\datasource_name-jdbc.xml

前置条件:

#1. 拷贝数据库驱动程序(sqljdbc4.jar等)到:C:\Oracle\Middleware\wlserver_10.3\server\lib

#2. 修改配置文件(D:\domains\base_domain\bin\setDomainEnv.cmd):在文件最后添加

set CLASSPATH=%PRE_CLASSPATH%;%WEBLOGIC_CLASSPATH%;%POST_CLASSPATH%;%WLP_POST_CLASSPATH%;%WL_HOME%\server\lib\sqljdbc4.jar;

配置数据源:(D:\domains\base_domain\config\config.xml)

  <jdbc-system-resource>
<name>fundamental</name>
<target>AdminServer</target>
<descriptor-file-name>jdbc/fundamental-jdbc.xml</descriptor-file-name>
</jdbc-system-resource>

D:\domains\base_domain\config\jdbc\fundamental-jdbc.xml:

<?xml version='1.0' encoding='UTF-8'?>
<jdbc-data-source xmlns="http://xmlns.oracle.com/weblogic/jdbc-data-source" xmlns:sec="http://xmlns.oracle.com/weblogic/security" xmlns:wls="http://xmlns.oracle.com/weblogic/security/wls" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.oracle.com/weblogic/jdbc-data-source http://xmlns.oracle.com/weblogic/jdbc-data-source/1.2/jdbc-data-source.xsd">
<name>fundamental</name>
<jdbc-driver-params>
<url>jdbc:sqlserver://localhost:1433</url>
<driver-name>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-name>
<properties>
<property>
<name>user</name>
<value>javaweb</value>
</property>
<property>
<name>databaseName</name>
<value>TSQLFundamentals2008</value>
</property>
</properties>
<password-encrypted>{AES}mC7MZTOcXIpmDSxDMdd7saPHBF01+jvvWuyeGNcUsc8=</password-encrypted>
</jdbc-driver-params>
<jdbc-connection-pool-params>
<test-table-name>SQL SELECT 1</test-table-name>
</jdbc-connection-pool-params>
<jdbc-data-source-params>
<jndi-name>fundamental</jndi-name>
<global-transactions-protocol>OnePhaseCommit</global-transactions-protocol>
</jdbc-data-source-params>
</jdbc-data-source>

4. NetBeans 创建web project: (index.jsp)

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="javax.sql.DataSource"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="javax.naming.Context"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>测试容器管理的数据源</title>
</head>
<body>
<h1>测试容器管理的数据源</h1>
<%
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup("fundamental");
Connection conn = ds.getConnection();
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from HR.Employees"); while (rs.next()) {
out.println(rs.getString(1) + ", " + rs.getString(2) + "<br/>");
} rs.close();
stmt.close();
conn.close();
%>
</body>
</html>

5. 部署到weblogic: (D:\domains\base_domain\config\config.xml)

  <app-deployment>
<name>dsTest</name>
<target>AdminServer</target>
<module-type>war</module-type>
<source-path>D:\ZDocuments\JIRA\NetBeans\Web\JavaEE Traditional\ch04\dsTest\build\web</source-path>
<security-dd-model>DDOnly</security-dd-model>
<staging-mode>nostage</staging-mode>
</app-deployment>

6. 浏览器访问:http://localhost:7001/dsTest/index.jsp