最新下载
热门教程
- 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 {
相关文章
- 免费漫画平台精选-免费看漫画的优质平台大全 02-16
- 千牛网页版登录-千牛工作台一键登录 02-16
- Sora官网入口地址在哪里-Sora官网入口地址全收录 02-16
- 汗汗漫画极速入口-汗汗漫画秒开无延迟 02-16
- 今日校园查成绩攻略-四六级成绩快速查询教程 02-16
- 哔哩哔哩网页版直达-bilibili网页版快捷登录 02-16