commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Dee <>
Subject PerUserPoolDataSource usage in a J2SE environment for discrete DBs
Date Fri, 05 Mar 2010 18:39:05 GMT

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, 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://";
String connstr2 = "jdbc:jtds:sqlserver://";

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" );


View this message in context:
Sent from the Commons - User mailing list archive at

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

View raw message