配置weblogic的connection pool和Data Source

本文档详细介绍了如何在WebLogic 7.0.4上配置Oracle 9.2.0.1数据库的连接池OraThinpool和数据源OraThinDS。包括设置JDBC URL、Driver Classname、用户名、密码以及测试代码展示如何通过JNDI查找并使用数据源进行数据库操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

os version:windwos2000 server
hostname:mytest

database:oracle 9.2.0.1
port:1521
table: test(a number(2))
user:system
password:oracle

weblogic version: 7.0.4
domain:mydomain
server:myserver
port:7001
WL_HOME:d:/bea/weblogic

1.配置connection pool
打開weblogic管理控制台[http://mytest:7001/console]
mydomain->services->jdbc->connection pools
新增一connection pool
name: OraThinpool
url: jdbc:oracle:thin:@mytest:1521:technet
Driver Classname: oracle.jdbc.driver.OracleDriver
properties:user=system
password: oracle
target: myserver
test table name: dual

2.配置Data Source
打開weblogic管理控制台[http://mytest:7001/console]
mydomain->services->jdbc->Data Source
新增一Data Source
name: OraThinDS
JNDI Name: jndi_orathinDS
Pool Name: OraThinPool
target: myserver

3.測試代碼
Context ctx = null;
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL,"t3://mytest:7001");
try {
ctx = new InitialContext(ht);

javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup ("jndi_orathinDS");
java.sql.Connection conn = ds.getConnection();

Statement stmt=conn.createStatement();
String sql="select a from test";
ResultSet rs=stmt.executeQuery(sql);
while (rs.next()){
int i=rs.getInt(1);
System.out.println(i);
}
}
catch(Exception e){
e.printStackTrace();
}
rs.close();
stmt.close();
conn.close();

4.附注
數據庫的jdbc驅動位置應該在環境變量classpath中出現,本例使用的驅動為classes12.zip
位於d:/bea/weblogic/server/lib
則classpath=d:/bea/weblogic/server/lib/classes12.zip;%CLASSPATH%
修改d:/bea/weblogic/server/bin/startWLS.cmd中的classpath後重新啟動weblogic即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值