commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dirk Verbeeck <>
Subject Re: DBCP and the ConnectionPoolDataSource Interface
Date Sat, 21 Feb 2004 13:11:18 GMT
There are 2 almost separate connection pool implementations in the 
DBCP distribution.

The first one is located in org.apache.commons.dbcp.*
Starting from DriverConnectionFactory it builds a PoolingDataSource 
called BasicDataSource (the default tomcat datasource).
More info can be found here:

It provides all pooling features for the DataSource.getConnection() 
method. (see configuration page for details)

The second pool implementation around the interface 
javax.sql.ConnectionPoolDataSource is located in:
It is mostly used for its "per user" connection pools.

<Resource auth="Container" name="jdbc/peruser" 
type="org.apache.commons.dbcp.datasources.PerUserPoolDataSource" />
<ResourceParams name="jdbc/peruser">

The dataSourceName refers to a datasource implementing the 
javax.sql.ConnectionPoolDataSource interface.
You can use a database specific implementation or the generic DBCP one:
<Resource auth="Container" name="jdbc/peruserCPDS" 
type="org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS" />
<ResourceParams name="jdbc/peruserCPDS">

If you need a pooled getConnection() methods use BasicDataSource 
otherwise use PerUserPoolDataSource (with DriverAdapterCPDS or a 
database specific ConnectionPoolDataSource)

One last remark, if you going to use the MySQL driver for the 
ConnectionPoolDataSource be aware of the following issue:


Fumo, Vince wrote:

> I have three different databases I need to manage and I want to use
> connection pooling datasources registered in JNDI as their commonality in my
> application. From what I can gather, if the JDBC driver from the db vendor
> has a DataSource implementation that implements ConnectionPoolDataSource, I
> can easily register it in JNDI. It's also my understanding that the
> management of the pool itself is not the responsibility of the individual
> JDBC driver. I'm hoping that DBCP can handle my management. 
> What I'd like to implement is a simple method  that will take a
> ConnectionPoolDataSource object, wrap it in pool management and return a
> PoolingDataSource object that I can then register in JNDI. 
> I've looked at the Dialog in the javadoc and I understand how to create a
> pool given a connection string (using the DriverConnectionFactory) but I'm
> not sure how to replace this ConnectionFactory with the
> ConnectionPoolDataSource object. I'm not even sure if this is what I should
> be doing.
> I'm sorry if this seems a simple question, but I've looked everywhere and I
> can't seem to find anything that references a connection between
> ConnectionPoolDataSource and DBCP (other than the reference in the javadoc
> for DriverAdapterCPDS.
> Thanks for your help.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message