I follow up the java doc java doc for datasource.
I am not understanding the below code snippt.
I create a connectionpooldatasource and register with jndi.
cpds.setServerName("creamer");
cpds.setDatabaseName("COFFEEBREAK");
cpds.setPortNumber(9040);
cpds.setDescription("Connection pooling for " + "COFFEEBREAK DBMS");
Context ctx = new InitialContext();
ctx.bind("jdbc/pool/fastCoffeeDB", cpds);
Now we can retrive this connection pool data source
Context ctx = new InitialContext();
ctx.lookup("jdbc/pool/fastCoffeeDB");
I create an another datasource and register it.
com.applogic.PooledDataSource ds = new
com.applogic.PooledDataSource();
ds.setDescription("produces pooled connections to COFFEEBREAK");
ds.setDataSourceName("jdbc/pool/fastCoffeeDB");
Context ctx = new InitialContext();
ctx.bind("jdbc/fastCoffeeDB", ds);
Now we can retrive this connection pool data source
ctx = new InitialContext();
ds = (DataSource)ctx.lookup("jdbc/fastCoffeeDB");
I am not clear about setDataSourceName.
We add ConnectionPoolDS into PoolDataSource.
when we retrive the datasource
ds = (DataSource)ctx.lookup("jdbc/fastCoffeeDB");
then the data soruce return from here is PoolDataSource type or ConnectionPoolDS type?.
using this
jdbc/pool/fastCoffeeDB JNDI you are directly pointing to COFFEEBREAK database.
in second JNDI
jdbc/fastCoffeeDB
you are using following statement
ds.setDataSourceName("jdbc/pool/fastCoffeeDB");
In the above you are pointing old JNDI name, this means you are indirectly points to COFFEEBREAK database
so from statement ds = (DataSource)ctx.lookup("jdbc/fastCoffeeDB"); you will get ConnectionPoolDS.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.