import java.sql.*;
import oracle.jdbc.pool.*;
class oracleConnMgr {
OracleDataSource ods;
oracleConnMgr() {
try {
ods = new OracleDataSource();
java.util.Properties prop = new java.util.Properties();
prop.setProperty("InitialLimit", "3");
prop.setProperty("MinLimit", "3");
prop.setProperty("MaxLimit", "5");
prop.setProperty("MaxStatementsLimit", "20");
String url = "jdbc:oracle:thin:@wcasbuild01.prod.oclc.org:2484/wcasbld.prod.oclc.org";
ods.setImplicitCachingEnabled(true);
ods.setURL(url);
ods.setUser("howards");
ods.setPassword("oclc*5439");
ods.setConnectionCachingEnabled(true);
ods.setConnectionCacheProperties (prop);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
try {
oracleConnMgr cm = new oracleConnMgr();
for (int i = 1; i <= 30; i++) {
Connection conn = cm.ods.getConnection();
ResultSet rst1= conn.createStatement().executeQuery("select sys_context('userenv','sid') from dual");
String sid = "";
while (rst1.next()) {
sid = rst1.getString(1);
}
PreparedStatement pst = conn.prepareStatement("select * from t");
ResultSet rst = pst.executeQuery();
rst.close();
pst.close();
ResultSet rset= conn.createStatement().executeQuery("select parse_calls,executions from v$sql where sql_id = '89km4qj1thh13'");
while (rset.next()) {
System.out.println("SID " + sid + " running, statement has been parsed " + rset.getString(1) + " times and executed " + rset.getString(2) + " times.");
}
conn.close();
}
}
catch (Exception e) {
e.printStackTrace();
}
}
}
Monday, October 22, 2007
Connection pool example
I was really surprised there were no working examples (albeit simple) in the Oracle documentation. Below is a simple connection pool (with cached statements that eliminate soft parsing)...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment