最新下载
热门教程
- 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 {
相关文章
- 《红色沙漠》六点钟信使获得方法介绍 10-20
- 《和平精英》吃鸡要不要开DX12-性能与画质解析 10-20
- 《红色沙漠》宠物机械鹰获得方法介绍 10-20
- 植物大战僵尸网页版入口-植物大战僵尸网页版在线试玩 10-20
- 《暗黑破坏神4》S13赛季改动汇总-全新玩法与系统详解 10-20
- poki宝玩热门游戏入口-Poki宝玩免费在线秒玩 10-20