File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes How to Bound JNDI names and references Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to Bound JNDI names and references" Watch "How to Bound JNDI names and references" New topic

How to Bound JNDI names and references

Neha Sharma
Ranch Hand

Joined: Jul 13, 2001
Posts: 126
Hi Guys,
I'm trying to do a JNDI lookup for my datasource in a servlet(No EJBs) which is being created in Websphere 4.0 enviornment.
I have created the JDBC driver, the datasource and their respective resource properties files. But I keep getting
nullpointer exception. From the Websphere documentation I read that I need to do bound JNDI Names and references. How do I accomplish that, Is it done programmatically ?
Can anybody give any lead on this.
my code is as follows
java.util.Properties parms = new java.util.Properties();
parms.setProperty(Context.INITIAL_CONTEXT_FACTORY, "");
javax.naming.Context ctx = new javax.naming.InitialContext(parms);
javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("jdbc/OracleDSN");
Connection Con = ds.getConnection();
chin josei

Joined: Jun 22, 2001
Posts: 25
U need to bind it to the JNDI tree.I have done it for Weblogic.
For Websphere also it might be similar
Herez what I have used.
Hashtable h1 = new Hashtable();
Context jndictx = new InitialContext(h1);
jndictx.rebind("JNDI Name",this);
Hope this helps
I agree. Here's the link:
subject: How to Bound JNDI names and references
It's not a secret anymore!