You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Vinicius Carvalho <vi...@sambatech.com.br> on 2009/11/18 14:01:29 UTC

Question on JNDI and DBCP

Hello there! I'm trying to register multiple datasources on the JNDI using
DBCP

Here's what I've done:

Reference refA = createRef(url,user,pwd);
Reference refB = createRef(url2,user2,pwd2);



ic.bind("java:/comp/env/jdbc/db1",refA);
ic.bind("java:/comp/env/jdbc/db2",refB);


private reference createRef(String url, String username, String password){

 Reference ref = new Reference("javax.sql.DataSource",
    "org.apache.commons.dbcp.BasicDataSourceFactory", null);
  ref.add(new StringRefAddr("driverClassName",
"org.apache.commons.dbcp.TesterDriver"));

  ref.add(new StringRefAddr("url", url));
  ref.add(new StringRefAddr("username", username));
  ref.add(new StringRefAddr("password", password));
  return ref;




}

The problem is that both context references points to the first datasource.
I thought that the JNDI would use the name part to bind a unique value, but
seems that both references turn to be the same (they both are
javax.sql.Datasource, BasicDatasourceFactory).

My question is how can I add multiple datasources under diferent jndi
locations?

Regards