weblogic 学习

一、 采用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());
  
  };
  
  %>
1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值