Devi

import javax.sql.DataSource;
import javax.naming.Context;
import javax.naming.InitialContext;

public Connection connectDb(String jndiLookupStr) throws java.sql.SQLException {

try {
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup(jndiLookupStr);
Connection conn = ds.getConnection();
if(conn == null){
System.out.println("Connection Object is nulll");
}
return conn;
} catch (Exception e) {
return null;
}
}

Sunil, zhang can try this code , to connect via JNDI ..but he shd run the code where the JNDI should be available to use..Zhang must be aware of it.

regards
deiveegarajan

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.