网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Java
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.JavaDoc,在 Java 的注释上做文章.
.试析J2EE与.NET时代的商业利润(转.
.EJB轻松进阶之八.
.谈谈J2SE中的序列化(一).
.JDBC编程基础--很不错的文章!.
.J2EE编程起步(3).
.在Eclipse 3.1体验J2SE 5.0新特性.
.CORBA编程.
.构建Java并发模型框架.
.Linux+Java=Lava(岩浆)?.
.Swing资源.
.使用PreparedStatement减少开发的.
.java 中添加一个全局快捷键.
.彻底明白Java的多线程-实现多线程.
.彻底学习Java语言中的覆盖和重载.
.将eclipse项目导入到Netbeans ID.
.SUN JAVA认证的内容和认知度.
.Apusic 应用服务器简介.
.基于Java IDL的分布式程序设计.
.Java编程思想读书笔记(第5-7章.

WebLogic7中的JDBC Pool的配置

发表日期:2008-1-5



  一、 采用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());
  
  };
  
  %>
上一篇:针对hibernate,jdbc,sql的思考 人气:1074
下一篇:JDBC和Hibernate来写入Blob型数据 人气:1152
浏览全部Java的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐