Java

本类阅读TOP10

·使用MyEclipse开发Struts框架的Hello World!(录像1)
·hibernate配置笔记
·AOP编程入门--Java篇
·linux下Tomcat 5.0.20 与 Apache 2 安装/集成/配置
·在win2003下整合了整合Tomcat5.5+ apache_2.0.53+ mod_jk_2.0.47.dll
·构建Linux下IDE环境--Eclipse篇
·Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台)
·ASP、JSP、PHP 三种技术比较
·Tomcat5.5.9的安装配置
·AWT GUI 设计笔记(二)

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
配置weblogic的connection pool和Data Source

作者:未知 来源:月光软件站 加入时间:2005-5-13 月光软件站

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即可




相关文章

相关软件