Java DB Conn Pool

联合创作 · 2023-09-29 14:18

Java DB Conn Pool 是一个 Java 的数据库连接池组件。

使用示例代码:

public class TestPool
{
public static void main (String[] args)
{
DataSource ds = null;
//PrintWriter log = null; //uncomment to turn on logging
try
{
//log = new PrintWriter(new FileWriter("dblog"), true); //uncomment to turn on logging
Properties p = new Properties();
p.setProperty("logLevel", "1"); //debug = 4, info = 3, warn = 2, error = 1, fatal = 0
p.setProperty("autoCommit", "false");
p.setProperty("description", "Oracle");
p.setProperty("driverClass", "oracle.jdbc.driver.OracleDriver");
p.setProperty("maxCount", "2");
p.setProperty("minCount", "1");
p.setProperty("user", "test");
p.setProperty("password", "test");
p.setProperty("url", "jdbc:oracle:thin:@127.0.0.1:1565:test");
p.setProperty("loginTimeout", "0"); //in seconds
p.setProperty("holdTimeout", "1000"); //in seconds
p.setProperty("waitTimeout", "10000"); //in milliseconds
p.setProperty("checkQuery", "select SYSDATE from dual");
p.setProperty("statementCacheSize", "10");

//ds = new RPDataSource(p, log); //use this instead of the next line to turn on logging
ds = new RPDataSource(p);
Connection con = ds.getConnection();
Statement s = con.createStatement();
ResultSet rs = s.executeQuery("select SYSDATE from dual");
if (rs.next())
{
System.out.println (rs.getString(1));
}
rs.close();
s.close();
con.close();
con = ds.getConnection();
s = con.createStatement();
rs = s.executeQuery ("select SYSDATE from dual");
if (rs.next())
{
System.out.println (rs.getString(1));
}
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
RPDataSource rp = (RPDataSource)ds;
rp.destroy();
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
浏览 20
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑 分享
举报