最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
一个连接池的例子(说明)
时间:2022-07-02 18:21:12 编辑:袖梨 来源:一聚教程网
这个连接池是直接从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:tempqingtuoDbLog.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 {
用法:
先设定自己的连接参数,在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:tempqingtuoDbLog.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 {
相关文章
- 幻兽帕鲁饲料箱怎么做 饲料箱制造方法介绍 07-31
- 燕云十六声天泉地位怎么晋升 天泉门派晋升方法 07-31
- 明末渊虚之羽龟纽金宝有什么用 龟纽金宝用途介绍 07-31
- 幻兽帕鲁怎么去掉无用词条 去掉无用词条方法介绍 07-31
- 人渣SCUM未安装EasyAntiCheat启动错误如何解决 解决方法一览 07-31
- 明末渊虚之羽羽族遗骸有什么用 羽族遗骸获取位置介绍 07-31