You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by AJ Weber <aw...@comcast.net> on 2012/09/27 20:34:20 UTC
[dbcp] newbie preparedStatement pooling question
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
Re: [dbcp] newbie preparedStatement pooling question
Posted by miten mehta <im...@yahoo.com>.
Hi,
Once you get connection from datasource/driver and call prepareStatement (sql) it will create / obtain one from pool as per API.
Also stackoverflow has discussion on it. The sql will be key in this case for the key pool and PreparedStatement the value.
Regards,
Miten.
________________________________
From: AJ Weber <aw...@comcast.net>
To: user@commons.apache.org
Sent: Friday, September 28, 2012 12:04 AM
Subject: [dbcp] newbie preparedStatement pooling question
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