commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Dee <mdichiapp...@cardeatech.com>
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
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" );

Thanks,
Mike


-- 
View this message in context: http://n4.nabble.com/PerUserPoolDataSource-usage-in-a-J2SE-environment-for-discrete-DBs-tp1579959p1579959.html
Sent from the Commons - User mailing list archive at Nabble.com.

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


Mime
View raw message