My code is unable to do lookup a JDBC resource using JNDI. I am getting the following exception:
[Root exception is javax.naming.NameNotFoundException: Context: ppp-14415Node01Cell/nodes/ppp-14415Node01/servers/server1, name: jdbc/admincob: First component in name admincob not found. [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]]
I have followed these 2 solution on SO, but still its not working
Websphere 6.1 to 7 how to update ibm-web-bnd.xmi to ibm-web-bnd.xml
How do I connect to a Websphere Datasource with a given JNDI name?
Here is my ibm-web-bnd.xml
<virtual-host name="default_host" />
<resource-ref name="jdbc/dbcob" binding-name="jdbc/admincob" />
and portion of web.xml
<resource-ref>
<description>
Datasource connection to db</description>
<res-ref-name>jdbc/dbcob</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
Here is the screenshot of the binding:
Lookup code:
Context initialContext = new InitialContext();
DataSource datasource = (DataSource) initialContext
.lookup("java:comp/env/jdbc/dbcob");
if (datasource != null) {
result = datasource.getConnection();
System.out.println("Data connection retrieved");
result.close();
} else {
System.err.println("Failed to lookup datasource.");
}
I am not sure what am I missing. Please help.