这个连接池是直接从jive中取出来的,进行了一下修改,使得连接参数直接在程序中设定而不是从属性文件中读取。
用法:
先设定自己的连接参数,在dbconnectiondefaultpool.java文件的loadproperties方法中。注意你也需要设定连接池的log文件的存放位置。
string driver="org.gjt.mm.mysql.driver";//这是使用的jdbc驱动
string server="jdbc:mysql://192.100.100.1/qingtuo";//使用的url
//string server="jdbc:mysql://192.168.0.1/qingtuo";
string username="qingtuo";
string password="qingtuo";
string minconnections="3";//最小连接数
string maxconnections="20";//最大连接数
string logpath="c:\\temp\\qingtuodblog.log";//日志文件位置
//string logpath="/tmp/qingtuodblog.log";
string connectiontimeout="0.5";//定时清除无用连接间隔(以天为单位)
然后
在你的程序中只需要将这个包com.qingtuo.db.pool import进来,再向下面这样用就行了。
connection con = null;
preparedstatement pstmt = null;
resultset rs=null;
try {
con = dbconnectionmanager.getconnection();
//这里写你的sql语句
}
catch (sqlexception sqle) {
throw sqle;
}
finally {
try {
pstmt.close();
}
catch (exception e) {
e.printstacktrace();
}
try {
con.close();
}
catch (exception e) {
e.printstacktrace();
}
}
优点
虽然很多应用服务器也有连接池,但这样做的好处是,更加通用一些。
