• Post Reply Bookmark Topic Watch Topic
  • New Topic

Not able to use my datasource using JNDI lookup

 
Neha Sharma
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
I'm trying the following code to access my datasource, which is created in websphere 4.0, and I'm getting a null pointer Exception. I've just created the DSN but in the websphere documentation it says you have to bind your dsn to the JNDI how do you do that ? do you perform this programmatically or is there a way to do it in websphere. Do I need to add anything in my code.
java.util.Properties parms = new java.util.Properties();
parms.setProperty Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
Context ctx = new javax.naming.InitialContext(parms);
ds = (javax.sql.DataSource)ctx.lookup("jdbc/OracleDSN");
Con = ds.getConnection();
}catch (NullPointerException ex) {out.println("NullPointerException Exception while creating the datasource");}
catch (Exception ex) {out.println("Exception while creating the datasource");}

Thanks
Neha

 
Craig Berry
Author
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To bind the datasource to the JNDI tree you need to provide a JNDI name if the Properties for the datasource. TBH I'm not sure how you managed to create a datasource without giving it a JNDI name as it's a required field.
Anyway, you can get the configuration panel from the admin console at the following location:
WebSphere Administration Domain -> Resources -> JDBC Drivers -> <OracleDriverName> -> Data Sources
------------------
Craig Berry
Author of Professional EJB
 
Neha Sharma
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Craig,
I didn't know just giving a JNDI name is called binding. I did do that, but it still gives me a null pointer exception. Can you check my code I've written above and tell me if I've missed something there.
Thanks
Neha
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!