Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to Bound JNDI names and references

 
Neha Sharma
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic