You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Mike Dee <md...@cardeatech.com> on 2010/03/05 19:39:05 UTC

PerUserPoolDataSource usage in a J2SE environment for discrete DBs

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


Re: [dbcp] Re: PerUserPoolDataSource usage in a J2SE environment for discrete DBs

Posted by Mike Dee <md...@cardeatech.com>.
Thanks for the response Phil.  I ended up downloading the source and came to
the same conclusion.  Also, ended up doing exactly what you said - created a
Map of pools.  Works fine.

I am curious as to how this is done in a J2EE environment (with JNDI).  From
my understanding, connection pooling in Tomcat (and possibly other J2EE
servers) makes use of dbcp.  Do you think they create a Map of pools too.

Mike

-- 
View this message in context: http://n4.nabble.com/PerUserPoolDataSource-usage-in-a-J2SE-environment-for-discrete-DBs-tp1579959p1583656.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


[dbcp] Re: PerUserPoolDataSource usage in a J2SE environment for discrete DBs

Posted by Phil Steitz <ph...@gmail.com>.
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