JNDI context lookup in Tomcat 4.0.3 from an application for JDBC connection.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Dan_Valiga
Posted On:   Tuesday, April 30, 2002 12:37 PM

I've been trying to get my application to run in Tomcat 4.0.3 but have not been able to access JNDI resources. ENVIRONMENT: Linux (Redhat 6.2) Tomcat 4.0.3 Apache (IBM's running through SSL -mod_jk- to Tomcat) JDK 1.3.1 I've read through the JNDI HOW-TO document and have set up the server.xml and WEB_INF/web.xml to reflect the database resource I configured. My only (limited) success so far has been accessing a context from a SERVLET. My application code is launched through the (org.apache.catalina.LifecycleListener) tag which is nested within my defined context in server.xml. I get an initial context back through    More>>

I've been trying to get my application to run in Tomcat 4.0.3 but have not been able to access
JNDI resources.



ENVIRONMENT:

Linux (Redhat 6.2)

Tomcat 4.0.3

Apache (IBM's running through SSL -mod_jk- to Tomcat)

JDK 1.3.1



I've read through the JNDI HOW-TO document and have set up the server.xml and
WEB_INF/web.xml to reflect the database resource I configured. My only (limited) success so far has
been accessing a context from a SERVLET.



My application code is launched through the (org.apache.catalina.LifecycleListener) tag
which is nested within my defined context in server.xml. I get an initial context back through
the call to:



			
Context ctx = new InitialContext();



which returns a context with two items populated:

			
java.naming.factory.initial = org.apache.naming.java.javaURLContextFactory
java.naming.factory.url.pkgs = org.apache.naming



At this point if I attempt to do a lookup of "java:comp/env" I get a naming Exception:

javax.naming.NameNotFoundException: Name java: is not bound in this Context



How can Tomcat populate the initial context and then not be able to access the JNDI registry with
it? At the very least java:comp/env should be found, right? I'm guessing that I am missing some
sort of JNDI configuration issue.





Here are pieces of my server.xml, web.xml, and code:





SERVER.XML

			













user
XXXXX


password
XXXXX


driverClassName
oracle.jdbc.driver.OracleDriver


driverName
jdbc:oracle:thin:@XXXXXXXXXXXXXXXXXXXX:1521:DS01






mail.smtp.host
localhost






WEB.XML

			

Database connection for myapp
jdbc/myappDb
javax.sql.DataSource
Container




CODE

			
...
Context initCtx = null;

try {
initCtx = new InitialContext(); //RETURNS context with two items populated
} catch (NamingException e) {
System.out.println("Couldn't build an initial context : " + e);
e.printStackTrace();
}

Context envCtx = null;
try {
str = "java:comp/env";
envCtx = (Context) initCtx.lookup(str); //FAILS!!! Can't find "java:comp" message
} catch(Exception ex) {
ex.printStackTrace();
}

// Look up our data source
str = "jdbc/myappDb";
DataSource ds = (DataSource) envCtx.lookup(str); //FAILS



THANKS for any help!
gs to format code blocks.

   <<Less

Re: JNDI context lookup in Tomcat 4.0.3 from an application for JDBC connection.

Posted By:   c_h  
Posted On:   Tuesday, April 30, 2002 01:04 PM

Hi, I had similar problem but the exception was raised when I did the lookup for DataSource. I solved my problem by placing the Oracle driver (classes12.jar) in %TOMCAT_INSTALL%commonlib directory.

Don't know if this will fix your problem. But you may want to double check the CLASSPATH used in Catalina's startup scripts.

About | Sitemap | Contact