wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes Servlet to db connection using JNDI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Servlet to db connection using JNDI" Watch "Servlet to db connection using JNDI" New topic
Author

Servlet to db connection using JNDI

Ian Whitelaw
Greenhorn

Joined: Mar 30, 2000
Posts: 13
I am trying to connect to an Oracle database from a servlet using a JNDI lookup and the DataSource interface.
The code I use is :

where "tisdev" is the name of the database.
This gives the following error:
javax.naming.NameNotFoundException:Missing node [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound]
How do I fix?
I've tried various strings in the lookup method, all with similar results.
I'm using JBuilder3.5 & Inprise App Server 4.0, (though my understanding is that none of my code runs on the app server?)Running the same code under iPlanet 6.0 works fine. Connecting via an EJB under Inprise also works fine. What am I missing?
madhavi narra
Greenhorn

Joined: Feb 01, 2003
Posts: 1
I have exactly same problem when I do lookout for Datasource.I am doing lookup as follows and am getting follwoing errors. I would be greatful if you can share your solution(if you found out) with me.
Context env = (Context) context.lookup("java:comp/env");
dataSource = ( DataSource )context.lookup("java:comp/env/jdbc/ssiDataSource");
javax.naming.NameNotFoundException: Missing Node - ssiDataSource
at com.inprise.j2ee.jndi.java.javaContext.internal_lookup(javaContext.java:511)
at com.inprise.j2ee.jndi.java.javaContext.internal_lookup(javaContext.java:521)
at com.inprise.j2ee.jndi.java.javaContext.internal_lookup(javaContext.java:521)
at com.inprise.j2ee.jndi.java.javaContext.internal_lookup(javaContext.java:521)
at com.inprise.j2ee.jndi.java.javaContext.internal_lookup(javaContext.java:521)
at com.inprise.j2ee.jndi.java.javaContext.lookup(javaContext.java:974)
at com.inprise.j2ee.jndi.java.javaContext.lookup(javaContext.java:979)


Madhu
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1134

Hi Ian and Madhu,
JNDI (as the name suggests) is an interface. Therefore it requires an implementation. And you need to register a lookup name with the implementation before a client can use that lookup name.
For example, I use a J2EE application server called OC4J (Oracle Container for J2EE). It has a JNDI implementation. When I start up this application server, it reads an XML (configuration) file that contains the lookup name for an Oracle datasource. It then registers that name with its JNDI implementation (also know as a "driver"). So after I start up OC4J, I can use code (similar to yours) in my client to obtain the datasource.
Now, what JNDI driver are you using, and how do you register the lookup name with that driver?
Hope this helps.
Good Luck,
Avi.
Ian Whitelaw
Greenhorn

Joined: Mar 30, 2000
Posts: 13
Wow! A response after nearly two and a half years!
Not surprisingly, I'm afraid I cannot remember the original problem too well, nor whether I ever found a solution. All I do remember is that the whole thing was very frustrating, that most people don't know what they're talking about most of the time, and that people's propensity for expressing an opinion is usually inversely proportional to the insight gained by the expression of that opinion (JavaRanch contributors excepted). Now that I'm the wrong side of forty (and therefore in the eyes of most corporate HR departments/IT managers/employment agencies far too old to learn anything new), I'm hoping to give up the whole IT malarky and emigrate to New Zealand to throw pots and sell them to the tourist hoardes looking to find Isengard or Edoras or any one of the innumerable Lord of the Rings sites. In the meantime, I'd better get back to supporting the dodgy piece of PL/SQL code written by some contractor who's long since left and is now fitting windows in Peterborough.
Anyway, good luck solving your problem. There's plenty of good stuff on the Ranch if you've time to look.
Ian
P.S. For non-UK readers and the geographically-challenged, the Peterborough in question is a (rather anonymous) town in SE England about an hour north of London by train.
Srini Parthasarathy
Greenhorn

Joined: Mar 24, 2004
Posts: 1
Avi,
I am using Oracle AS 10g. I am trying to use the "DataSourceUserManager" provided with it. I configured this to be the user manager for my app, and and set all initialization params (of which datasource is one). When I try to go to the security section of my app thru OEM, I get a NamingException that the JNDI name for the datasource could not be found. When I looked at the logs, I got the follg. message:
Error instantiating application at file:/usr/oracle/infra/j2ee/OC4J_SECURITY/applications/B2B_Demo_App.ear: Error initializing
userManager 'com.evermind.sql.DataSourceUserManager': NamingException: Need to specify class name in environment or system property, or
as an applet parameter, or in an application resource file: java.naming.factory.initial
What could be the problem? I thought all I need to do was to configure a data source and provide it to the DataSourceUserManager. OC4J doesn't seem to be storing and retrieving the JNDI name. Or am I missing something? Any help is appreciated. Thanks.
Originally posted by Avi Abrami:
Hi Ian and Madhu,
JNDI (as the name suggests) is an interface. Therefore it requires an implementation. And you need to register a lookup name with the implementation before a client can use that lookup name.
For example, I use a J2EE application server called OC4J (Oracle Container for J2EE). It has a JNDI implementation. When I start up this application server, it reads an XML (configuration) file that contains the lookup name for an Oracle datasource. It then registers that name with its JNDI implementation (also know as a "driver"). So after I start up OC4J, I can use code (similar to yours) in my client to obtain the datasource.
Now, what JNDI driver are you using, and how do you register the lookup name with that driver?
Hope this helps.
Good Luck,
Avi.

 
 
subject: Servlet to db connection using JNDI