commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sitowitz, Paul" <PSitow...@verisign.com>
Subject RE: [dbcp] question regarding connection pooling and prepared statements
Date Thu, 20 Oct 2005 17:26:28 GMT
Bernie,

The following demonstrates how to turn on PreparedStatement pooling in
DBCP (assuming that you already have a PoolableConnectionFactory called
"pcf"):

GenericKeyedObjectPool.Config config 
	= new GenericKeyedObjectPool.Config();

// use config to set any configuration parameters for the Pstmt Pool
// when creating the GenericKeyedObjectPoolFactory
//   ex: config.maxIdle = 10; config.maxActive = 20; etc..

// Can either be done via the setter (as shown here) or during the 
// construction of your PoolableConnectionFactory instance. Just make
// sure that the Statement Pool Factory is set BEFORE any connections
are
// actually borrowed from the connection pool. The latter method
// (during construction) will ensure that this condition is satsified. 
pcf.setStatementPoolFactory
	(new GenericKeyedObjectPoolFactory(null, config));

That's it! Pstmt pooling is now enabled on a per-connection basis. If
you do not set the Statement Pool Factory on your
PoolableConnectionFactory instance (it will remain null), no pooling of
PreparedStatements will occur.

Paul

-----Original Message-----
From: Durfee, Bernard [mailto:Bernard.Durfee@suny.edu] 
Sent: Thursday, October 20, 2005 9:17 AM
To: Jakarta Commons Users List
Subject: RE: [dbcp] question regarding connection pooling and prepared
statements

How do I turn on PreparedStatement pooling?

Bernie



> -----Original Message-----
> From: Sitowitz, Paul [mailto:PSitowitz@verisign.com] 
> Sent: Wednesday, October 19, 2005 4:40 PM
> To: Jakarta Commons Users List
> Subject: RE: [dbcp] question regarding connection pooling and 
> prepared statements
> 
> 
> Bill,
> 
> Prepared Statements are on a per-connection level. In fact, 
> if you turn
> on DBCP PrepareStatement pooling, a separate PrepareStatement 
> pool will
> be maintained for each Db connection. The PreparedStatement 
> therefore is
> tightly coupled with the connection that created it.
> 
> Paul
> 
> -----Original Message-----
> From: Hudson, Bill [mailto:bhudson@extol.com] 
> Sent: Wednesday, October 19, 2005 3:34 PM
> To: commons-user@jakarta.apache.org
> Subject: [dbcp] question regarding connection pooling and prepared
> statements
> 
>  
> Question: I am trying to determine if commons-dbcp provides this
> functionality: Can a prepared statement be generated against a
> connection obtained from the a connection pool, say "connection x".
> Then can connection x be returned to the pool, and at a later time can
> the prepared statement be used with a different connection, say
> "connection y", obtained from the same connection pool (both 
> connections
> against same database, using the same driver).  In other words, if I
> maintain a reference to a prepared statement, will that reference be
> valid regardless of what connection the underlying pool provides to me
> over the course of my application's execution time?
> 
> To phrase the question differently: are prepared statements on a
> per-connection level, or are they "global" to all connections in the
> connection pool?
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 
> 

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



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


Mime
View raw message