高分求教 struts+oracle 如何配置连接池? onlyxu(未透露姓名男子) 连接池一般由容器提供,配置一下就可以使用----------------------------------------------谢谢你,你说的我也知道,可是如何调用呢 ,你能给我一个小小的例子吗 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 配置:--------------------------------------------------- 第一步,去oracle下载最新的 oracle JDBC driver。 一共2个文件,ojdbc14.jar和nls_charset12.zip。 第一个文件是驱动程序所在,第二个是支持国际化的包。 接下来,把这两个文件加入 WLS 的 classpath。 修改 Bea\Weblogic\server\bin\startWLS.cmd(或者相应的Unix启动文件,.sh结尾的), 在文件开头加入 PRE_CLASSPATH=C:\ojdbc14.jar;C:\nls_charset12.zip。注意文件的路径。 最后可以考虑把Bea\Weblogic\server\lib\classes12.zip删除,我不保证正确性,只是怕有兼容性问题。 最后,启动weblogic server,进入console,在Connection Pool里边,填入一下资料。 General栏目: Name:MyOracle_CP URL:jdbc:oracle:thin:@server:port:sid (自己按照情况修改!) 比如:jdbc:oracle:thin:@192.168.0.2:1521:Crystal DriverName:oracle.jdbc.driver.OracleDriver Properties user=SYS (这里是用户,最好不要用SYS,SYSTEM等系统用户) ACL Name: (空) password: 用户密码 Connection栏目: CapacityIncrement = 50 MaxCapacity = 100 Capacity Increment: 5 Login Delay Seconds: 0 seconds Refresh Period: 10 minutes Supports Local Transaction 不要打勾 Allow Shrinking 打勾 Shrink Period: 15 minutes Prepared Statement Cache Size: 5 Test栏目: TestTableName:SCOTT.EMP (这里需要改动,适应你自己的表,wls用来做连接测试用的) TestConnectionsOnReleasetrue 打勾 TestConnectionsOnReservetrue 打勾 最后,点击Apply,然后去Targets,选中你的server,点右箭头,使你的server进入Chosen栏目,最后Apply。(如图) 查看dos窗口,是否有错误,如果没有则继续,如果有的话,自己查看填写的内容。 至此,Connection Pool已经配置完毕。 接下来,该配置(TX)DataSource了。 从昨天的panel里边,单击DataSources/TX DataSources,进入配置界面。 1。单击Configure a new JDBC Tx Data Source..配置新的datasource 2。填入以下数据: Name: MyDataSource (自己随便起的) JNDI: jdbc/OracleDS (这里就是你lookup的时候填入的名字,自己想吧。 Pool Name: MyOracle_CP (一定要对应你的Connection Pool的 Name) 把后边两项打上勾。 第一个是模拟2阶提交模式,如果数据库driver本身不支持的话。(就是XA标准,分布式提交) 第二个是 行预读。 点击Create,然后去Targets里边,把你的 server放入chosen,点击apply。。 配置完成 最后检查你的DataSource是否已经成功部属: 进入你的server的JNDI Tree,很容易就可以看到的。:)。 使用:通过jndi找到数据源,再从数据源中获得连接----------------------------------------------------------------------------------import java.sql.*;import java.util.*;import javax.naming.*;import javax.sql.*;public class JdbcTest { public static void main(String[] args) { DataSource ds = null; Context ctx = null; Connection myConn = null; try { /* 获得WebLogic ServerJNDI初始上下文信息 */ ctx = getInitialContext(); /* 建立数据源对象 */ ds = (javax.sql.DataSource) ctx.lookup("jdbc/OracleDS"); } catch (Exception E) { System.out.println("Init Error: " + E); } Statement myStatement = null; ResultSet myResultSet = null; try { //建立连接 myConn = ds.getConnection(); // 建立语句对象 myStatement = myConn.createStatement(); //建立结果集对象 myResultSet = myStatement.executeQuery( "SELECT deptname from dept" ); //遍历结果集对象,访问每一条记录,输出full_name字段 while (myResultSet.next()) { System.out.println("the employee full name is " + myResultSet.getString("deptname")); } //关闭结果集 myResultSet.close(); } catch (SQLException e) { System.out.println("Error code = " + e.getErrorCode()); System.out.println("Error message = " + e.getMessage()); } finally { try { // close the Statement object using the close() method if (myStatement != null) { myStatement.close(); } // close the Connection object using the close() method if (myConn != null) { myConn.close(); } } catch (SQLException e) { System.out.println("Error code = " + e.getErrorCode()); System.out.println("Error message = " + e.getMessage()); } } } private static Context getInitialContext() throws Exception { String url = "t3://localhost:7001"; String user = "weblogic"; String password = "weblogic"; Properties properties = null; try { properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); properties.put(Context.PROVIDER_URL, url); if (user != null) { properties.put(Context.SECURITY_PRINCIPAL, user); properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password); } return new InitialContext(properties); } catch (Exception e) { throw e; } }} 有关struts2 的模型驱动 有达人帮忙解决下 javamail的问题 Caused by: org.hibernate.MappingException: Unknown entity:异常 第六十行错误怎么回事 java 对文本文件的修改 struts多表单验证问题 宠物等级增长的问题?来向大家咨询了,先谢谢各位 电脑和用户名如何邦定 JDK1.5的RMI可以不用生成Stub文件? 如何关闭jb7中的历史记录功能 【精华贴】请大家把自己的精典Java 性能优化技巧贴上来! 关于JDBC和sqlserver连接的问题(高手路过请进来帮忙看看
---------------------------------------------------
第一步,去oracle下载最新的 oracle JDBC driver。
一共2个文件,ojdbc14.jar和nls_charset12.zip。
第一个文件是驱动程序所在,第二个是支持国际化的包。
接下来,把这两个文件加入 WLS 的 classpath。
修改 Bea\Weblogic\server\bin\startWLS.cmd(或者相应的Unix启动文件,.sh结尾的),
在文件开头加入 PRE_CLASSPATH=C:\ojdbc14.jar;C:\nls_charset12.zip。注意文件的路径。
最后可以考虑把Bea\Weblogic\server\lib\classes12.zip删除,我不保证正确性,只是怕有兼容性问题。
最后,启动weblogic server,进入console,在Connection Pool里边,填入一下资料。
General栏目:
Name:MyOracle_CP
URL:jdbc:oracle:thin:@server:port:sid (自己按照情况修改!)
比如:jdbc:oracle:thin:@192.168.0.2:1521:Crystal
DriverName:oracle.jdbc.driver.OracleDriver
Properties
user=SYS (这里是用户,最好不要用SYS,SYSTEM等系统用户)
ACL Name: (空)
password: 用户密码
Connection栏目:
CapacityIncrement = 50
MaxCapacity = 100
Capacity Increment: 5
Login Delay Seconds: 0 seconds
Refresh Period: 10 minutes
Supports Local Transaction 不要打勾
Allow Shrinking 打勾
Shrink Period: 15 minutes
Prepared Statement Cache Size: 5
Test栏目:
TestTableName:SCOTT.EMP (这里需要改动,适应你自己的表,wls用来做连接测试用的)
TestConnectionsOnReleasetrue 打勾
TestConnectionsOnReservetrue 打勾
最后,点击Apply,然后去Targets,选中你的server,点右箭头,使你的server进入Chosen栏目,最后Apply。(如图)
查看dos窗口,是否有错误,如果没有则继续,如果有的话,自己查看填写的内容。
至此,Connection Pool已经配置完毕。
接下来,该配置(TX)DataSource了。
从昨天的panel里边,单击DataSources/TX DataSources,进入配置界面。
1。单击Configure a new JDBC Tx Data Source..配置新的datasource
2。填入以下数据:
Name: MyDataSource (自己随便起的)
JNDI: jdbc/OracleDS (这里就是你lookup的时候填入的名字,自己想吧。
Pool Name: MyOracle_CP (一定要对应你的Connection Pool的 Name)
把后边两项打上勾。
第一个是模拟2阶提交模式,如果数据库driver本身不支持的话。(就是XA标准,分布式提交)
第二个是 行预读。
点击Create,然后去Targets里边,把你的 server放入chosen,点击apply。。
配置完成
最后检查你的DataSource是否已经成功部属:
进入你的server的JNDI Tree,很容易就可以看到的。:)。
通过jndi找到数据源,再从数据源中获得连接
----------------------------------------------------------------------------------
import java.sql.*;
import java.util.*;
import javax.naming.*;
import javax.sql.*;public class JdbcTest { public static void main(String[] args) {
DataSource ds = null;
Context ctx = null;
Connection myConn = null;
try {
/* 获得WebLogic ServerJNDI初始上下文信息
*/
ctx = getInitialContext();
/* 建立数据源对象
*/
ds = (javax.sql.DataSource)
ctx.lookup("jdbc/OracleDS");
}
catch (Exception E) {
System.out.println("Init Error: " + E);
}
Statement myStatement = null;
ResultSet myResultSet = null;
try {
//建立连接
myConn = ds.getConnection();
// 建立语句对象
myStatement = myConn.createStatement();
//建立结果集对象
myResultSet = myStatement.executeQuery(
"SELECT deptname from dept"
);
//遍历结果集对象,访问每一条记录,输出full_name字段
while (myResultSet.next()) {
System.out.println("the employee full name is " +
myResultSet.getString("deptname"));
}
//关闭结果集
myResultSet.close();
}
catch (SQLException e) {
System.out.println("Error code = " + e.getErrorCode());
System.out.println("Error message = " + e.getMessage());
}
finally {
try {
// close the Statement object using the close() method
if (myStatement != null) {
myStatement.close();
}
// close the Connection object using the close() method
if (myConn != null) {
myConn.close();
}
}
catch (SQLException e) {
System.out.println("Error code = " + e.getErrorCode());
System.out.println("Error message = " + e.getMessage());
}
} } private static Context getInitialContext() throws Exception {
String url = "t3://localhost:7001";
String user = "weblogic";
String password = "weblogic";
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS,
password == null ? "" : password);
}
return new InitialContext(properties);
}
catch (Exception e) {
throw e;
}
}}