permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes mysql class not found exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "mysql class not found exception" Watch "mysql class not found exception" New topic
Author

mysql class not found exception

Aneek Banerjee
Ranch Hand

Joined: Jun 20, 2012
Posts: 61

Hi I am building a web application.
For that I have a user registration page and I want to store the user inputs into mysql database.
I have added the required .jar(mysql-connector-java5.1.22-bin.jar) file also.But when I check for the connection it is giving me a "class not found".

Error->root cause
javax.servlet.ServletException: java.lang.Error: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver.


The code I written in my JSP for connection is given below.

<%@page import="java.sql.*" %>

<%! public static Connection connect(){

try{

Class.forName("com.mysql.jdbc.Driver").newInstance();
return DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb","root","password");

}
catch(Exception e){

throw new Error(e);
}
}

public static boolean close(Connection c){

try{
c.close();
return true;
}
catch(Exception e){

return false;
}


}
%>

Please help....

Thanks! in advance.

Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 722
You may want to download the required jar file here:
http://www.jarfinder.com/index.php/java/info/com.mysql.jdbc.Driver
and then add it as a library to your IDE.
Aneek Banerjee
Ranch Hand

Joined: Jun 20, 2012
Posts: 61

I tried the same also but still getting the same error.
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 722
Are you using Tomcat server?
Maybe, put the jar file in your project's Web-INF/lib.
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1526
Aneek, has this anything to do with SCJP/OCPJP?


Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: mysql class not found exception
 
Similar Threads
Query about Connection interface
SQLException: Callable statments not supported.
Connecting to a MySQL DB
java jdbc
resource bundle