Answers inline...

James Blashill wrote:

Hello,

I'm hoping someone can clarify some things about configuring DBCP for
me. I've been reading through the documentation on the web page and I
seem to be missing something. :(

I am trying to make use of configuration properties specified here:

http://jakarta.apache.org/commons/dbcp/configuration.html

However, I am not sure exactly how to do that. Here is my code for
creating a DataSource.

        ObjectPool connectionPool = new GenericObjectPool(null);
        ConnectionFactory connectionFactory = new
DriverManagerConnectionFactory(MessageFormat.format(connectUri, args),
user, password);
        PoolableConnectionFactory poolableConnectionFactory = new
PoolableConnectionFactory(connectionFactory, connectionPool, null, null,
false, true);
        PoolingDataSource dataSource = new
PoolingDataSource(connectionPool);

Looking through javadocs, I realized that most of the configuration
options above can be specified in the constructors for either
GenericObjectPool or PoolableConnectionFactory. However, I still have a
few problems:

1) How is prepared statement pooling enabled/disabled? The above link
describes a poolPreparedStatements property that I have figure out where
to specify. It seems to me that if you pass a KeyedObjectPool as the
third parameter of PoolableConnectionFactory's constructor you will
enable prepared statement pooling. Is this correct?

You pass a KeyedObjectPoolFactory as the third parameter. Each PoolableConnection needs its own KeyedObjectPool to pool the prepared statements so the PoolableConnectionFactory needs a factory to create these pools.


2) How do I specify the loginTimeout value? PoolingDataSource gives me
an UnsupportedOperationException when I try to invoke it's
setLoginTimeout() method.

You can use a DataSourceConnectionFactory and set the login timeout on the original non-pooling datasource. Also set the maxWait property.


3) Just out of curiosity, what goes into the Properties parameter for
the constructor of DriverManagerConnectionFactory? Parameters you want
to use to initialize your driver?

I will add the following javadoc: /** * Constructor for DriverManagerConnectionFactory. * @param connectUri a database url of the form * <code> jdbc:<em>subprotocol</em>:<em>subname</em></code> * @param props a list of arbitrary string tag/value pairs as * connection arguments; normally at least a "user" and "password" * property should be included. */

Sorry for the long email, but I appreciate any words of wisdom out
there! :)

Hope this helps

Cheers
Dirk



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to