JavaDBConnPool是一个Java的数据库连接池组件。
使用示例代码:
publicclassTestPool{publicstaticvoidmain(String[]args){DataSourceds=null;//PrintWriterlog=null;//uncommenttoturnonloggingtry{//log=newPrintWriter(newFileWriter("dblog"),true);//uncommenttoturnonloggingPropertiesp=newProperties();p.setProperty("logLevel","1");//debug=4,info=3,warn=2,error=1,fatal=0p.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");//insecondsp.setProperty("holdTimeout","1000");//insecondsp.setProperty("waitTimeout","10000");//inmillisecondsp.setProperty("checkQuery","selectSYSDATEfromdual");p.setProperty("statementCacheSize","10");//ds=newRPDataSource(p,log);//usethisinsteadofthenextlinetoturnonloggingds=newRPDataSource(p);Connectioncon=ds.getConnection();Statements=con.createStatement();ResultSetrs=s.executeQuery("selectSYSDATEfromdual");if(rs.next()){System.out.println(rs.getString(1));}rs.close();s.close();con.close();con=ds.getConnection();s=con.createStatement();rs=s.executeQuery("selectSYSDATEfromdual");if(rs.next()){System.out.println(rs.getString(1));}}catch(Exceptione){e.printStackTrace();}finally{try{RPDataSourcerp=(RPDataSource)ds;rp.destroy();}catch(Exceptione){e.printStackTrace();}}}}
评论