File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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, "com.ibm.websphere.naming.WsnInitialContextFactory");
javax.naming.Context ctx = new javax.naming.InitialContext(parms);
javax.sql.DataSource ds = (javax.sql.DataSource)ctx.lookup("jdbc/OracleDSN");
Connection Con = ds.getConnection();
Thanks
Neha
chin josei
Greenhorn

Joined: Jun 22, 2001
Posts: 25
Hii..
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();
h1.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
h1.put(Context.PROVIDER_URL,"t3://localhost:7001");
Context jndictx = new InitialContext(h1);
jndictx.rebind("JNDI Name",this);
Hope this helps
chin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Bound JNDI names and references