WebLogic7中的JDBC Pool的配置

發表于:2007-06-22來源:作者:點擊數: 標簽:
一、 采用Microsoft的JDBC Driver 1 到www.microsoft.com上下載“Microsoft SQL Server 2000 Driver for JDBC”并安裝 2 安裝后,在安裝的目錄中有三個jar文件包 msbase.jar msutil.jar ms sqlserver .jar 建議將其拷貝出來放置到%WL_HOME%\server\lib目錄中

   
  一、 采用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。原因如下:
  
 ?。?)在以后的版本中,weblogic 將不再對jDriver of mssql server進行支持
  
 ?。?)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 aclearcase/" target="_blank" >ccounts");
  
  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());
  
  };
  
  %>

原文轉自:http://www.anti-gravitydesign.com

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97