File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes JNDI problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JNDI problem" Watch "JNDI problem" New topic
Author

JNDI problem

Ricky James
Ranch Hand

Joined: Mar 26, 2007
Posts: 83
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

Joined: Apr 14, 2004
Posts: 10336

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?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ricky James
Ranch Hand

Joined: Mar 26, 2007
Posts: 83


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

Joined: Feb 25, 2007
Posts: 1638

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


apigee, a better way to API!
Ricky James
Ranch Hand

Joined: Mar 26, 2007
Posts: 83
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

Joined: Apr 14, 2004
Posts: 10336


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.
 
Don't get me started about those stupid light bulbs.
 
subject: JNDI problem
 
Similar Threads
javac : Compiling a .JAVA file which uses other classes in it
Why does this Swing program doesn't show anything?
my inverted index not successfull
Intelligent Agents
error running a program from The Java Tutorial