You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by James Blashill <JB...@rim.com> on 2004/07/23 23:13:32 UTC

[DBCP] configuration confusion..

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?

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

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?

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

Thanks,

James


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


Re: [DBCP] configuration confusion..

Posted by Dirk Verbeeck <di...@pandora.be>.
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: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org