Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JNDI problem

 
Ricky James
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying a sample application that uses JNDI. But when I try to run one servlet I get the following error:

C:\Program Files\Apache Group\Tomcat 5.5\webapps\jndi-datasource\WEB-INF\classes
\com\servlet>javac JndiDatasourceServlet.java
JndiDatasourceServlet.java:15: package com.sql does not exist
import com.sql.JndiDatasource;
^
JndiDatasourceServlet.java:35: cannot find symbol
symbol : class JndiDatasource
location: class com.servlet.JndiDatasourceServlet
JndiDatasource jnd = new JndiDatasource();
^
JndiDatasourceServlet.java:35: cannot find symbol
symbol : class JndiDatasource
location: class com.servlet.JndiDatasourceServlet
JndiDatasource jnd = new JndiDatasource();
^
3 errors

Is this a problem with the classpath? Would really appreciate help in this regards.
Thanks
Ricky
[ March 26, 2007: Message edited by: Ricky James ]
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to include whichever Jar contains the class com.sql.JndiDatasource in your web application's classpath. I'm not familiar with it - is it something you have written yourself?
 
Ricky James
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


No I haven't written it myself. I am just trying to copy and run the code. Although the instructions simply say:
mysql-connector-java-5.0.4-bin.jar) must be available in Tomcat's CLASSPATH (e.g. $Tomcat_Home/common/lib).
I have copy-pasted the jar file in the lib directory and also added the path
C:\Program Files\Apache Group\Tomcat 5.5\common\lib;
to TOMCAT_HOME.
But it still is not working.
Ricky
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
C:\Program Files\Apache Group\Tomcat 5.5\webapps\jndi-datasource\WEB-INF\classes
\com\servlet>javac JndiDatasourceServlet.java

You are compiling the servlet code and not running it.
You need to specify the jars in the classpath of javac using the flag -classpath
eg:
javac -classpath /localdisk/jars/j2ee.jar JndiDatasourceServlet.java
 
Ricky James
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are compiling the servlet code and not running it.
You need to specify the jars in the classpath of javac using the flag -classpath
eg:
javac -classpath /localdisk/jars/j2ee.jar JndiDatasourceServlet.java


Thanks for the reply Nitesh but I didn't really understand this. Can you be a little more specific please?

I mean what should "-classpath /localdisk/jars/j2ee.jar" really point to?

Ricky
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I mean what should "-classpath /localdisk/jars/j2ee.jar" really point to?

It needs to point to the jars containing all the classes your code uses. So you need to include the jar file that includes the class com.servlet.JndiDatasource. As far as I am aware this is not a class that is part of the MySQL driver, not is it part of J2EE or Tomcat. So you need to find where it is and include it in your classpath.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic