File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Websphere and the fly likes DB JNDI lookup WAS 4.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "DB JNDI lookup WAS 4.0" Watch "DB JNDI lookup WAS 4.0" New topic

DB JNDI lookup WAS 4.0

Nijeesh Balan
Ranch Hand

Joined: Oct 09, 2000
Posts: 116
We are doing a JNDI Lookup in our utility class like this.
Context ctx = new InitialContext();
DataSource ds = ctx.lookup("jdbc/dbSource");
But in the sample code i have seen, the lookup looks like this.
DataSource ds = ctx.lookup("java:comp/env/jdbc/dbSource");
1. Is there a difference in these two lookups?
2. When we do the second lookup, it throws the naming exception. This might be because for Web Modules -> Resource References name and the jndi names are different. but I am not sure.
Please let me know if you have some inputs.

Thanks & Regards,

Thanks & Regards,<br />Nijeesh.
Kyle Brown
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
The top one looks it up from the global JNDI namespace. The second one looks up a name defined in the ejb-jar.xml as being local to that particular EJB (which is bound to a name in the global namespace during deployment). Read Richard Monson-Haefel's EJB book for an explanation of how JNDI works and what the two mean.

Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at for other WebSphere information.
I agree. Here's the link:
subject: DB JNDI lookup WAS 4.0
It's not a secret anymore!