aspose file tools*
The moose likes JDBC and the fly likes ClassNotFoundException. 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 "ClassNotFoundException." Watch "ClassNotFoundException." New topic
Author

ClassNotFoundException.

Ravikumar Jambunathan
Ranch Hand

Joined: Aug 25, 2003
Posts: 66
hi all,
i have set the classpath for classes12.zip.
i unzipped all the class files in classes12.zip and rejar into classes12.jar and have put it in %TOMCAT-HOME%/common/lib.
when i want to load the jdbc-driver using Class.forName(), it thorws this exception. what could be the problem?
help me please. thanks in advance.
tomcat version 1.4.18
java version j2sdk1.4.1_01.
----------------------
Ravi
Sun Certified Programmer.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8898

Have you restarted tomcat after you jared the file?


Groovy
Sainudheen Mydeen
Ranch Hand

Joined: Aug 18, 2003
Posts: 218
Originally posted by Ravikumar Jambunathan:

i have set the classpath for classes12.zip.

classpath is set to classes12.zip or classes12.jar?
-Sainudheen
Ravikumar Jambunathan
Ranch Hand

Joined: Aug 25, 2003
Posts: 66
thanks guys.
yes pradeep, i did.
my classpath settings,
c:\oracle\ora81\jdbc\lib\classes12.zip.
due to the exception, i tried by setting one more classpath variable for classes12.jar as follws.
c:\tomcat\common\lib\classes12.jar.
awating your advice.
---------------------
Ravi
Sun Certified Programmer.
Sainudheen Mydeen
Ranch Hand

Joined: Aug 18, 2003
Posts: 218
It will be more clear if you post the exception and portion of your code.
Thanks
-Sainudheen
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
I know this doesn't really address your immediate concern, but just for future reference you don't need to unzip and then jar the files. You can simply rename "classes12.zip" as "classes12.jar". It's the very same format.
As Sainudheen said, you need to post the exception and the portion of the code. The most likely cause is a simply name error. Make sure you are using "oracle.jdbc.driver.OracleDriver" as the driver name (case sensitive). Another possibility is that there was a problem in the unzip/jar process (another reason to simply rename it).
Also, why are you setting the classpath if you are using Tomcat? If you are running a web application, Tomcat will set the classpath automatically.
Ravikumar Jambunathan
Ranch Hand

Joined: Aug 25, 2003
Posts: 66
thanks guys. I have renamed the classes12.zip into jar. This is the latest state of my problem.
here is my code. %TOMCAT-HOME%/webapps/MyServlets/WEB-INF/src
public class App_addNew extends HttpServlet{
String driver,url;
public void init() throws ServletException{
driver = getServletConfig().getInitParameter("driver");
url = getServletConfig().getInitParameter("url");

if (driver == null || url == null){
throw new UnavailableException("Driver not Specified");
}
try{
Class.forName(driver);
}catch (ClassNotFoundException cnfe){
throw new ServletException("Driver not Found");
}
}
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
Connection conn=null;

try{
conn=DriverManager.getConnection(url,"scott","tiger");
PreparedStatement pstmt=conn.prepareStatement( "INSERT INTO dept VALUES ?,?,?)");
pstmt.setInt(1,100);
pstmt.setString(2,"EDP");
pstmt.setString(3,"SIN");
pstmt.executeUpdate();
pstmt.close();
} catch (Exception ex){
throw new ServletException(ex);
}
finally {
try{
if (conn != null) conn.close();
insertCheck(res);
System.out.println("after method-call, now i am here");

} catch(Exception ex){
throw new ServletException(ex);
}
}//Finally

}//doget
public void insertCheck(HttpServletResponse res) throws ServletException,IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<html><body><h2><b>\"Insertion Successfull!, Good.\"</b></h2></body></html>");
out.close();
}
}//class
this my descripter, %TOMCAT-HOME%/webapps/MyServlets/WEB-INF
<servlet>
<servlet-name>App_addNew</servlet-name>
<servlet-class>App_addNew</servlet-class>
<init-param>
<param-name>driver</param-name>
<param-value>oracle.jdbc.driver.OracleDriver</param-value>
</init-param>
<init-param>
<param-name>url</param-name>
<param-value>jdbc racle:thin:@localhost:1521:test</param-value>
</init-param>
</servlet>
and have given few lines of the exception,
javax.servlet.ServletException: Driver not Found
at App_addNew.init(App_addNew.java:22)
at javax.servlet.GenericServlet.init(GenericServlet.java:256)
at org.apache.catalina.core.StandardWrapper.loadServlet
Sorry friends, it is quite long reply. thanks for your time.
awaiting your advice.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Applications running within application servers typically ignore the system classpath. This allows the app server to serve multiple applications all with different class paths.
Since you're using just Tomcat and only have to worry about the servlet container, the prefferd way to include external jars is to place it in the WEB-INF/lib directory. The server will automatically put it on the web applciations classpath for you.
You still need to make sure you drop the jar in that directory, not the zip, since zip files are typically not automatically loaded for you.
Dave
Ravikumar Jambunathan
Ranch Hand

Joined: Aug 25, 2003
Posts: 66
thanks dave,
i have put the classes12.jar in my applicaiton directory under WEB-INF/lib.
But still it throws "Driver Not Found Exception".
I have tried all the possibilities as far as i know.But i can not solve the problem.What could be the problem?.
Your advice would be a great help.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I'd try a few small things so that you can rule out what the problem isn't.
Add the driver name to the exception sent, so that it reads "Driver not found: "+driver. Make sure you're loading what you think you are.
Also, try instantiating the driver by hand. This is usually a bad idea, so remeber to remove it later:

Both of these should work, but I'd be interested in hearing why they might fail.
Dave
Ravikumar Jambunathan
Ranch Hand

Joined: Aug 25, 2003
Posts: 66
hi dave,
i tried as you said. Still it throws the exception stating that oracle.jdbc.driver.OracleDriver not found.
Secondly,whan i instantiate driver as you suggested, it throws java.lang.NoClassDefFound- oracle/jdbc/driver/OracleDriver.
I really do not understand!!! where i am going wrong.
thanks for your time and effort.
-----------------
Ravi
Ravikumar Jambunathan
Ranch Hand

Joined: Aug 25, 2003
Posts: 66
hi,
when i browsing back the discussions related to above subject exception, if we put oracle.jar in WEB-INF/lib, server can access the jdbc driver.
Can anybody tell me where do i find oracle.jar?
regards.
Ravikumar Jambunathan
Ranch Hand

Joined: Aug 25, 2003
Posts: 66
hi,
when i am browsing back the discussions related to above subject exception, i understand that if we put oracle.jar in WEB-INF/lib, server can access the jdbc driver.
Can anybody tell me where do i find oracle.jar?
regards.
Sainudheen Mydeen
Ranch Hand

Joined: Aug 18, 2003
Posts: 218
Hi RaviKumar
Eventhough this is not a good approach, just try this. Extract classes12.zip file into your WEB-INF/classes folder of your sample application. Just make sure WEB-INF/classes/oracle/jdbc/driver/OracleDriver.class file exists. Then you will be OK with your program. If this works fine you should not have problem using classes12.jar under the lib folder.
-Sainudheen
Greg Donahue
Greenhorn

Joined: Oct 07, 2003
Posts: 24
This sounds like a classpath problem. In your program, try printing out the classpath by doing:
System.getProperty("java.class.path");
You should see the classpath you've specified. If not, you need to set it from inside (I'll give you two guesses as to how you do that).
Are you importing this driver? Do the import commands work?


vi veri veniversum vivus vici
Greg Donahue
Greenhorn

Joined: Oct 07, 2003
Posts: 24
Ahem. Sorry. Do:
System.out.println(System.getProperty("java.class.path"));
Ravikumar Jambunathan
Ranch Hand

Joined: Aug 25, 2003
Posts: 66
thanks mydeen,
i have tried as you said, but it still throws exception.
My God!, it really put me in mess....
Sainudheen Mydeen
Ranch Hand

Joined: Aug 18, 2003
Posts: 218
Eventhough this is not a good approach, just try this. Extract classes12.zip file into your WEB-INF/classes folder of your sample application. Just make sure WEB-INF/classes/oracle/jdbc/driver/OracleDriver.class file exists. Then you will be OK with your program.
-Sainudheen

I assume you are not getting ClassNotFound Exception now. Now replace

to

and try. Hope this work.
-Sainudheen
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassNotFoundException.
 
Similar Threads
JDBC Driver in Tomcat 4.0
Oracle Version Required by WebSphere 3.5.5
JSP - Oracle connectivity
using oracle thin diver, tomcat 5.5.9
jdbc and netbeans problem