Forums Register Login

Tomcat 7 ClassNotFound Exception

+Pie Number of slices to send: Send
Hi, guys...
I met a problem recently, that is, my JSP file cannot connect to my localhost oracle XE 10g db.
below is part of my code:

Driver driver=null;
public Connection getConnect(){
if(driver==null)
Class.forName("oracle.jdbc.OracleDriver");
Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/XE","secret","secret");
return conn;
}

I started tomcat7.0.5, and then I tried to view that JSP file, but I get the problem.

An error occurred at line: 12 in the jsp file: /testJsp.jsp
Unhandled exception type ClassNotFoundException
9:
10: public Connection getConnect(){
11: if(driver==null)
12: Class.forName("oracle.jdbc.OracleDriver");
13: Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/XE","SYSTEM","z_blue1009");
14: return conn;


An error occurred at line: 13 in the jsp file: /testJsp.jsp
Unhandled exception type SQLException
10: public Connection getConnect(){
11: if(driver==null)
12: Class.forName("oracle.jdbc.OracleDriver");
13: Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/XE","SYSTEM","z_blue1009");
14: return conn;
15: }

I have tried many ways to solve the problem, yet I cannot solve the problem.
What I have tried:
1. Set the ClassPath (but my laptop is win7, and there is no ClassPath in the Environment Variables)
2. copy the ojdbc14.jar to WEB-INF/lib (but there is no lib folder in the WEB-INF, I create it and paste the jar file...not working)
3. copy the ojdbc14.jar to [JAVA-HOME]\jre\lib\ext\...not working
4. change the class path from oracle.jdbc.driver.OracleDriver to oracle.jdbc.OracleDriver...not working
5. change the URL from jdbc:oracle:thin:@localhost:1521:xe to jdbc:oracle:thin:@//localhost:1521/XE...not working

But I didn't meet such problem before when I'm using the older version of XAMPP.
What is the problem actually and how to solve it? Thanks
+Pie Number of slices to send: Send
Normally JSP should used for UI rendering and nothing more. You should place your oracle driver jar file in the WEB-INF/lib folder. Import the necessary classes in your class files and then attempt to connect. Also, you need to enclose your code within a try-catch block to handle SQLException that may be thrown, when trying to connect to the database.
+Pie Number of slices to send: Send
actually I did put try-catch block at the beginning, but it still displays the same error. therefore, i simplified the code.
so, you means I should put the ojdbc14.jar under WEB-INF/lib folder?
but I'm not sure whether I should put it in the ROOT/WEB-INF/lib or ROOT/myWeb/WEB-INF/lib?
the JSP file is in the myWeb folder, and I need to create WEB-INF and lib folders inside?
+Pie Number of slices to send: Send
You should definitely use try-catch block. You need to place the driver' jar file within your web application' WEB-INF/lib folder. You have to create the lib folder if it is absent. I also believe, that oracle.jdbc.OracleDriver is not the correct driver class. Please try to identify the correct driver class. Please checn the package name(s) too.
1
+Pie Number of slices to send: Send
oracle.jdbc.driver.OracleDriver
but don't take my word for it, open the JAR file and verify that the class exists.
And then the entire population worshiped me like unto a god. Well, me and this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 4608 times.
Similar Threads
servlet jdbc
java.sql.SQLException: No suitable driver found
JSP MSSQL - Connection Problem
class not found exception
NoClassDefFoundError
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:33:45.