You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Mike Starkie <sk...@yahoo.com> on 2005/03/16 00:11:04 UTC
DBCP: how to get reference to statement pool
I am writing some learning tests to verify and see
that my statements are being pooled and I was
wondering if there was a way to obtain a reference to
the KeyedObjectPool stored inside a PooledConnection.
I was looking through the code and didn't see an easy
way.
Here is what I'm trying to do:
GenericObjectPool gPool = new
GenericObjectPool();
Properties props = new Properties();
props.setProperty("User", "");
props.setProperty("Password", "");
ConnectionFactory cf =
new DriverConnectionFactory(new
com.mysql.jdbc.Driver(),
"jdbc:mysql:///test", props);
// use a pool to pool our stored procedures
GenericKeyedObjectPoolFactory kof =
new GenericKeyedObjectPoolFactory(null);
PoolableConnectionFactory pcf = new
PoolableConnectionFactory(cf, gPool,
kof, null, false, true);
PoolingDriver pd = new PoolingDriver();
pd.registerPool("driverexample", gPool);
for(int i = 0; i < 5; i++) {
gPool.addObject();
}
System.out.println(
"Number of idle connections in
driverexample: "
+ gPool.getNumIdle());
Connection conn = DriverManager.getConnection(
"jdbc:apache:commons:dbcp:driverexample");
Statement s = conn.createStatement();
ResultSet rs = s.executeQuery("SELECT * FROM
PET");
TestAll.printResults(rs);
// assert that the keyed statement pool has
one active object
--
The information contained in this email along with all attachments is confidential and is not to be shared without my permission and prior knowledge of who will be viewing it's contents including all attachments.
__________________________________
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org