点击这里给我发消息 点击这里给我发消息

WebLogic7中的JDBC Pool的配置

添加时间:2013-12-7
    相关阅读: 数据库 SQL MSSQL Oracle Windows 系统

  一、 采用Microsoft的JDBC Driver
  
  1 到www.microsoft.com上下载“Microsoft SQL Server 2000 Driver for JDBC”并安装
  
  2 安装后,在安装的目录中有三个jar文件包
  msbase.jar
  msutil.jar
  mssqlserver.jar
  
  建议将其拷贝出来放置到%WL_HOME%\server\lib目录中(其实随意,但附后的classpath中要指明)
  
  3 将3个jar包加入到classpath中,改startWLS.cmd,“set CLASSPATH=”后插入%WL_HOME%\server\lib\msbase.jar;%WL_HOME%\server\lib\msutil.jar;%WL_HOME%\server\lib\mssqlserver.jar;
  **
  注意:用weblogic7最好在创建domain前更改上面的设置。否则有可能出现不可预知的问题。
  
  4 确认MSSQLServer的端口号(这点比较重要)
  And to find the port number where your instance is running, run the
  server network utility and select the server instance and select the
  TCP/IP. When you click the properties button, it will show the port.
  
  5 启动WebLogic
  
  6 打开IE,在地址栏中输入:http://localhost:7001/console
  
  7 输入用户名和密码
  
  8 在左边的目录树中选中Services->JDBC->Connection Pools,单击右侧的Configure a new JDBC Connection Pool.,输入以下信息:
  
  Configuration->General页:
  Name = MSSQLServerConnectionPool
  URL = jdbc:microsoft:sqlserver://newsserv:1433;DatabaseName=wjw_test (注意端口号填第5步中看到的port)
  Driver classname =com.microsoft.jdbc.sqlserver.SQLServerDriver
  Properties :user=sa
  
  password = sa的密码
  
  单击Create建立连接池。
  
  9 Connection属性设置
  
  Configuration->Connections页:
  
  将Initial Capacity由1置为1 (视需求)
  
  将Maximum Capacity由1置为10(视需求)
  
  10 Targets->Server页:
  
  将myserver(服务器名称)移至右侧的列表中,但击单击Apply
  
  11 配置数据源
  
  . 在左边的目录树中选中Services->JDBC->Data Sources(或者TXData Sources),单击右侧的Configure a new JDBC Connection Pool.,输入以下信息:
  
  Configuration->General页:
  Name = SQLServer Tx Data Source
  JNDI Name = SQLServer
  Pool Name = MSSQLServerConnectionPool
  
  选中Row Prefetch Enabled
  
  单击Create建立数据源。
  
  12 Targets->Server页:
  
  将myserver(服务器名称)移至右侧的列表中,但击单击Apply,配置完毕。
  
  13 reboot server
  
  二、采用WebLogic的JDBC Driver for SQL Server
  
  1确认MSSQLServer的端口号(这点比较重要)
  And to find the port number where your instance is running, run the
  server network utility and select the server instance and select the
  TCP/IP. When you click the properties button, it will show the port.
  
  2 启动WebLogic
  
  3 打开IE,在地址栏中输入:http://localhost:7001/console
  
  4 输入用户名和密码
  
  5 在左边的目录树中选中Services->JDBC->Connection Pools,单击右侧的Configure a new JDBC Connection Pool.,输入以下信息:
  
  Configuration->General页:
  Name = WLSQLServerConnectionPool
  URL = jdbc:weblogic:mssqlserver4:northwind@localhost:2040
  Driver classname = weblogic.jdbc.mssqlserver4.Driver
  Properties :user=sa
  password = sa的密码
  
  单击Create建立连接池。
  
  6 Connection属性设置
  Configuration->Connections页:
  将Initial Capacity由1置为10 (视需求)
  将Maximum Capacity由1置为10(视需求)
  
  7 Targets->Server页:
  
  将myserver(服务器名称)移至右侧的列表中,但击单击Apply
  
  8 配置数据源
  
  . 在左边的目录树中选中Services->JDBC->Data Sources(或者TXData Sources),单击右侧的Configure a new JDBC Connection Pool.,输入以下信息:
  Configuration->General页:
  Name = SQLServer Tx Data Source
  JNDI Name = SQLServer
  Pool Name = WLSQLServerConnectionPool
  选中Emulate Two-Phase Commit for non-XA Driver和Row Prefetch Enabled
  
  单击Create建立数据源。
  
  9 Targets->Server页:
  
  将myserver(服务器名称)移至右侧的列表中,但击单击Apply,配置完毕。
  
  10 reboot server
  
  Re:WebLogic中SQL Server2000的JDBC Pool配置
  
  上面的配置文档很不错,不过个人建议,在采用 ms sql server数据库的系统,尽量不要使用weblogic jDriver或ms mssql driver。原因如下:
  
  (1)在以后的版本中,weblogic 将不再对jDriver of mssql server进行支持
  
  (1)ms mssql driver对于Image和text类型(也就是blob和clob类型)的数据查询,支持不好。
  
  所以,尽量采用第三方的ms sql server driver。只是第三方driver多有使用时间限制。
   
  三、WebLogic中的Oracle的JDBC Driver 的配置
  
  To setup a Connection Pool
  
  0. To update the Oracle Thin Driver bundled with WebLogic Server
  set CLASSPATH=%ORACLE_HOME%\jdbc\lib\classes12.zip;%WL_HOME%\lib\weblogic.jar;%CLASSPATH% (Windows)
  
  1. go to Services/JDBC/Connection Pools page of the weblogic console.
  
  2. Click Configure a new JDBC Connection Pool
  
  3. Fill in the information as following (suppose you are using the oracle jdbc thin driver)
  
  Name: testPool
  URL: jdbcracle:thin:@150.0.5.130:1521:ORACLE
  Driver: oracle.jdbc.driver.OracleDriver
  Properties:user=user1
  password=pass1
  
  4. Click the create button
  
  5. Config the connection property by using the connection tab.
  
  6. Click to the targets tab, select the server that will use this connection pool
  
  7. Create a datasource that use the connection pool
  Name: myDataSource
  JNDI Name: myDataSource
  Pool Name: testPool
  
  8. On targets tab, configure the server to use this datasource
  
  四、连接数据库代码
  
  Based on the above configuration, you can get a connection by using
  
  Context ctx = null;
  Hashtable ht = new Hashtable();
  ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
  ht.put(Context.PROVIDER_URL, "t3://127.0.0.1:7001");//127.0.0.1:7001是Weblogic的地址已经端口
  try {
  ctx = new InitialContext(ht);
  javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup ("myDataSource");
  java.sql.Connection conn = ds.getConnection();
  }
  ...
  
  To use direct connection
  
  //Instantiate the driver:
  driver = (Driver)Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
  //Make the connection:
  con = driver.connect("jdbcracle:thin:@150.0.5.130:1521:ORACLE", user1, pass1);
  
  使用jsp代码调用数据 下面是测试JDBC jsp1.jsp文件的内容:
  
  <%@ page contentType="text/html; charset=GBK" %>
  
  <!--测试数据源-->
  
  <%@ page import="javax.naming.Context" %>
  
  <%@ page import="javax.sql.DataSource"%>
  
  <%@ page import="javax.naming.InitialContext"%>
  
  <%@ page import="java.sql.*"%>
  
  <%
  
  DataSource ds = null;
  
  try{
  
  Context ctx = null;
  
  Hashtable ht = new Hashtable();
  
  ht.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
  
  ht.put(Context.PROVIDER_URL, "t3://pkucs-wjw:7001");
  
  try {
  
  ctx = new InitialContext(ht);
  
  ds = (javax.sql.DataSource) ctx.lookup ("jdbc/mssql");
  
  //从Context中lookup数据源。
  
  if(ds!=null)
  
  {
  
  out.println("已经获得DataSource!");
  
  out.println("<br>");
  
  Connection conn = ds.getConnection();
  
  Statement stmt=conn.createStatement();
  
  ResultSet rst=stmt.executeQuery("select * from accounts");
  
  out.println("以下是从数据库中读取出来的数据");
  
  while(rst.next())
  
  {
  
  out.println("bookName:"+rst.getString("id"));
  
  out.println("<br>");
  
  }
  
  }
  
  else
  
  out.println("连接失败!");
  
  }
  
  catch(Exception ne) {
  
  out.println(ne);
  
  }
  
  }
  
  catch(Exception ex){
  
  System.out.println(ex.getMessage());
  
  };
  
  %>
咨询热线:020-85648757 85648755 85648616 0755-27912581 客服:020-85648756 0755-27912581 业务传真:020-32579052
广州市网景网络科技有限公司 Copyright◎2003-2008 Veelink.com. All Rights Reserved.
广州商务地址:广东省广州市黄埔大道中203号(海景园区)海景花园C栋501室
= 深圳商务地址:深圳市宝源路华丰宝源大厦606
研发中心:广东广州市天河软件园海景园区 粤ICP备05103322号 工商注册