wood burning stoves 2.0*
The moose likes Websphere and the fly likes How many JNDI lookup for datasource in websphere Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Websphere
Bookmark "How many JNDI lookup for datasource in websphere" Watch "How many JNDI lookup for datasource in websphere" New topic
Author

How many JNDI lookup for datasource in websphere

khan gul
Ranch Hand

Joined: Jan 27, 2011
Posts: 30
I have a Question on JNDI lookup for datasource in websphere. My understanding is that if you have configured a connection pool on server like web sphere then the JDNI binding should occur once to initialize the DataSource object. Then later multiple threads can use this single DataSource object and call the getConnection() to get new connection from the pool. Is it correct?

java code below:


private static OLBDataSource instance = null;
private DataSource dataSource = null;

//make sure there is only one instance of OLBDataSource. aali
static {
try {
instance = new OLBDataSource();
} catch (NamingException e) {
instance = null;
}
}


private OLBDataSource() throws NamingException {
try {
Properties params = new Properties();
params.setProperty(Context.INITIAL_CONTEXT_FACTORY, WSN_INITIAL_CONTEXT_FACTORY);

// Look up the datasource configured on the server.
InitialContext context = new javax.naming.InitialContext(params);
dataSource = (DataSource) context.lookup("jdbc/myDB");

}catch


public static DataSource getMyConnection(){
return dataSource;
}


//Now multiple threads can call the above getMyConnection() method and then call getConnection() to get unique connection from the thread pool.

Is my understanding correct?

 
Consider Paul's rocket mass heater.
 
subject: How many JNDI lookup for datasource in websphere
 
Similar Threads
ServeltContextListener for DataSource
JNDI design question
database access outside of servlet container
Synchronize DataSource Instance?
new to EJB