commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Phil Steitz <phil.ste...@gmail.com>
Subject [dbcp] Re: PerUserPoolDataSource usage in a J2SE environment for discrete DBs
Date Sun, 07 Mar 2010 15:43:27 GMT
Mike Dee wrote:
> Is PerUserPoolDataSource a good option for pooling connections for multiple
> databases?  Note the environment is a J2SE app - not a web app, so there is
> no JNDI.
> 
> From the sample code (see
> http://commons.apache.org/dbcp/api-1.4/index.html), it looks like the same
> url (connection string which supplies the db name), is used for all
> connections.  In this case, however, each database has a different name,
> different username, and different password.
> 
> I may naively try something like this, but it doesn't seem like it would
> work.  Anyway, this code hopefully gives an idea of what I'd like to do.
> 
> String jdbcClass = "net.sourceforge.jtds.jdbc.Driver";
> String connstr1 = "jdbc:jtds:sqlserver://127.0.0.1:1433";
> String connstr2 = "jdbc:jtds:sqlserver://127.0.0.1:1433";
> 
> PerUserPoolDataSource pool = new PerUserPoolDataSource();
> 
> DriverAdapterCPDS cpds1 = new DriverAdapterCPDS();
> cpds1.setDriver( jdbcClass );
> cpds1.setUrl( connstr1 );
> cpds1.setUser( "user1" );
> cpds1.setPassword( "pass1" );
> 	        
> pool.setConnectionPoolDataSource( cpds1 );
>            
> DriverAdapterCPDS cpds2 = new DriverAdapterCPDS();
> cpds2.setDriver( jdbcClass );
> cpds2.setUrl( connstr2 );
> cpds2.setUser( "user2" );
> cpds2.setPassword( "pass2" );
> 	        
> pool.setConnectionPoolDataSource( cpds2 );
> 
> Connection conn1 = pool.getConnection( "user1", "pass1" );
> Connection conn2 = pool.getConnection( "user2", "pass2" );

Sorry for the delayed response.  Prefixing the subject line with the
component name - in this case [dbcp] - helps get a quicker response.

What you are trying to do is not currently supported.  Your example
above shows what the problem is - the PerUserPoolDataSource has only
one connectionPoolDataSource property, which is shared across pools.

If you don't need to share properties across pools, you are probably
best off just setting up a map of pools that you manage directly
(have a look at the PerUserPoolDataSource code to see how this can
be done).

Feel free to open a JIRA enhancement request for this feature here:
http://commons.apache.org/dbcp/issue-tracking.html

Phil


> 
> Thanks,
> Mike
> 
> 


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


Mime
View raw message