当前位置: 技术问答>java相关
Jsp连接池
来源: 互联网 发布时间:2015-06-12
本文导语: 各位大虾: 本人想用连接池做一个连接数据库的bean,JDK+tomcat,请问如何实现? 谢谢!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | public class ConnPool { private static final int defaultMaxConnection...
各位大虾:
本人想用连接池做一个连接数据库的bean,JDK+tomcat,请问如何实现?
谢谢!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
本人想用连接池做一个连接数据库的bean,JDK+tomcat,请问如何实现?
谢谢!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
public class ConnPool {
private static final int defaultMaxConnections=3;//默认最大连接对象数;
private Vector freeConnections;//存放还未被配置出去的连接对象;
private Hashtable boundConnections;//存放目前正被使用的连接对象;
private String driverName;
private String jdbcURL;
private String username;
private String password;
private int maxConnections;//最大连接对象数;
public ConnPool(int numConnections) {
maxConnections=numConnections;
boundConnections=null;
freeConnections=null;
driverName="";
jdbcURL="";
username="";
password="";
}
public ConnPool() {
this(defaultMaxConnections);
}
public void openDB(String drvName,String url,String uname,String passwd) throws SQLException {
try {
boundConnections=new Hashtable(maxConnections);
freeConnections=new Vector(maxConnections);
Class.forName(drvName);
for(int i=0;i
private static final int defaultMaxConnections=3;//默认最大连接对象数;
private Vector freeConnections;//存放还未被配置出去的连接对象;
private Hashtable boundConnections;//存放目前正被使用的连接对象;
private String driverName;
private String jdbcURL;
private String username;
private String password;
private int maxConnections;//最大连接对象数;
public ConnPool(int numConnections) {
maxConnections=numConnections;
boundConnections=null;
freeConnections=null;
driverName="";
jdbcURL="";
username="";
password="";
}
public ConnPool() {
this(defaultMaxConnections);
}
public void openDB(String drvName,String url,String uname,String passwd) throws SQLException {
try {
boundConnections=new Hashtable(maxConnections);
freeConnections=new Vector(maxConnections);
Class.forName(drvName);
for(int i=0;i