commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From AJ Weber <awe...@comcast.net>
Subject [dbcp] newbie preparedStatement pooling question
Date Thu, 27 Sep 2012 18:34:20 GMT
I _did_ try Google, I promise.  There are a few examples of this, but 
they're not documented enough that I fully understand proper use of this...

It appears that I can enable pooling of preparedStatements by "simply" 
including an ObjectPoolFactory in the PoolableConnectionFactory constructor:

KeyedObjectPoolFactory stmtPoolFactory = new 
GenericKeyedObjectPoolFactory(null);
new PoolableConnectionFactory(connectionFactory, connectionPool,
                         stmtPoolFactory, null, false, true, 
Connection.TRANSACTION_READ_COMMITTED);

(I suppose the first question is please confirm that is all I need to do 
for initial-setup?)

But how do I add & retrieve preparedStatements to/from the pool?

Should my method always call conn.prepareStatement("update..."); and in 
the background if a previously-prepared statement is available, it'll be 
used otherwise it's sent to the DB as normal?  Do I just "close" the 
prepared statement normally, and again, the prepared statement will be 
returned (or added) to the pool automatically?

When managing my own jdbc connection, I would typically prepare the 
statements once, in some kind of init method and tuck them away in a 
private variable, so they were available throughout the remainder of the 
class/program's lifetime.  Calling conn.prepareStatement( ) every time I 
want to [re-]use a statement just feels counter-intuitive somehow.

Thanks for bearing-with my newbie questions.

-AJ


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message