Hi, The code segment which i used is the following.
public Connection getConnection() throws javax.ejb.EJBException, java.sql.SQLException {
InitialContext initCtx = null;
try {
initCtx = new InitialContext();
DataSource ds = (javax.sql.DataSource)initCtx.lookup("sba");
return ds.getConnection();
}catch(NamingException ne) {
System.out.println("Exception at getConnection() method in AttributeManagerBean class");
throw new EJBException(ne);
}finally {
try {
if(initCtx != null) initCtx.close();
}catch(NamingException ne) {
System.out.println("Error closing context: " + ne);
throw new EJBException(ne);
}
}
}
Here, 'sba' is the datasource name which is seen in the WebSphere admin console. I created a driver by name 'sba' and then installed it and created datasource. no the urlprefix is "jdbc

b2"
Do I have to append the database server machine ip to this..? Please advice me whether my code is correct, and do I have to get an InitialContext object in the ejbCreate method.
In the above method, i tried to created an initial context in the following way too.
Properties h = new Properties();
h.put(javax.naming.Context.PROVIDER_URL,"iiop://localhost:900");
h.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
initCtx = new InitialContext(h);
When I try to use this getConnection() method from my
servlet, its throwing the following exception(s)
java.rmi.ServerException: RemoteException occurred in server
thread; nested exception is: com.ibm.ejs.container.UncheckedException: ; nested exception is: java.lang.ClassCastException: com.ibm.ejs.ns.jndi.CNContextImpl
Pl. do advice me how to proceed.
Thanks in advance
Praveen