在bean里,用oracle的pool,getPooledConnection();应该在构造函数里建立,还在其实里?释放开pool是不是应该在 finalize() 里? 你的getPooledConnection()应该是单独的方法,构造函数里面应该做初始化连接池对象用,释放开pool你只要断开连接就可以了!容器会自动回收CONNECTION对象的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 调用getPooledConnection()在构造函数里面?还是放到单独的方法里? 这种得数据库得连接应该专门做个类。在finally里把result,statement,和connectionclose掉就行了。 import java.sql.*;import javax.sql.*;import oracle.jdbc.driver.*;import oracle.jdbc.pool.*;class CCache1{ public static void main (String args []) throws SQLException { OracleConnectionCacheImpl ods = new OracleConnectionCacheImpl(); ods.setURL("jdbc:oracle:oci8:@"); ods.setUser("scott"); ods.setPassword("tiger"); // Set the Max Limit ods.setMaxLimit (3); Connection conn1 = null; conn1 = ods.getConnection(); if (conn1 != null) System.out.println("Connection 1 " + " Succeeded!"); else System.out.println("Connection 1 " + " Failed !!!"); Connection conn2 = null; conn2 = ods.getConnection(); if (conn2 != null) System.out.println("Connection 2 " + " Succeeded!"); else System.out.println("Connection 2 " + " Failed !!!"); Connection conn3 = null; conn3 = ods.getConnection(); if (conn3 != null) System.out.println("Connection 3 " + " Succeeded!"); else System.out.println("Connection 3 " + " Failed !!!"); Connection conn4 = null; conn4 = ods.getConnection(); if (conn4 != null) System.out.println("Connection 4 " + " Succeeded!"); else System.out.println("Connection 4 " + " Failed !!!"); Connection conn5 = null; conn5 = ods.getConnection(); if (conn5 != null) System.out.println("Connection 5 " + " Succeeded!"); else System.out.println("Connection 5 " + " Failed !!!"); System.out.println("Active size : " + ods.getActiveSize()); System.out.println("Cache Size is " + ods.getCacheSize()); // Close 3 logical Connections conn1.close(); conn2.close(); conn3.close(); System.out.println("Active size : " + ods.getActiveSize()); System.out.println("Cache Size is " + ods.getCacheSize()); // close the Data Source ods.close(); System.out.println("Active size : " + ods.getActiveSize()); System.out.println("Cache Size is " + ods.getCacheSize()); }}例子自己看看 关于jboss的login-config.xml的配置文件 如何获得网站的所有链接地址? java2word的问题??????急急 页面缓冲,应该怎么去做 jsp中的上传文件 linux下上传文件自动解压缩 对于客户端提交过来的文件流如何判断其大小 TOMCAT下自己写的BEAN应该放在什么目录? 想入java web方向了,求点书籍 请问 java怎么和go进行跨语言通信? 大侠帮帮小弟,分不是问题阿,急,在线等待 tomcat打开后,怎样自动执行一段程序?
在finally里把result,statement,和connectionclose掉就行了。
import javax.sql.*;
import oracle.jdbc.driver.*;
import oracle.jdbc.pool.*;class CCache1
{
public static void main (String args [])
throws SQLException
{
OracleConnectionCacheImpl ods = new OracleConnectionCacheImpl();
ods.setURL("jdbc:oracle:oci8:@");
ods.setUser("scott");
ods.setPassword("tiger"); // Set the Max Limit
ods.setMaxLimit (3); Connection conn1 = null;
conn1 = ods.getConnection();
if (conn1 != null)
System.out.println("Connection 1 " + " Succeeded!");
else
System.out.println("Connection 1 " + " Failed !!!"); Connection conn2 = null;
conn2 = ods.getConnection();
if (conn2 != null)
System.out.println("Connection 2 " + " Succeeded!");
else
System.out.println("Connection 2 " + " Failed !!!"); Connection conn3 = null;
conn3 = ods.getConnection();
if (conn3 != null)
System.out.println("Connection 3 " + " Succeeded!");
else
System.out.println("Connection 3 " + " Failed !!!"); Connection conn4 = null;
conn4 = ods.getConnection();
if (conn4 != null)
System.out.println("Connection 4 " + " Succeeded!");
else
System.out.println("Connection 4 " + " Failed !!!"); Connection conn5 = null;
conn5 = ods.getConnection();
if (conn5 != null)
System.out.println("Connection 5 " + " Succeeded!");
else
System.out.println("Connection 5 " + " Failed !!!");
System.out.println("Active size : " + ods.getActiveSize());
System.out.println("Cache Size is " + ods.getCacheSize()); // Close 3 logical Connections
conn1.close();
conn2.close();
conn3.close(); System.out.println("Active size : " + ods.getActiveSize());
System.out.println("Cache Size is " + ods.getCacheSize()); // close the Data Source
ods.close(); System.out.println("Active size : " + ods.getActiveSize());
System.out.println("Cache Size is " + ods.getCacheSize());
}
}例子自己看看