Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

mysql class not found exception

 
Aneek Banerjee
Ranch Hand
Posts: 61
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1254
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 61
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried the same also but still getting the same error.
 
Himai Minh
Ranch Hand
Posts: 1254
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you using Tomcat server?
Maybe, put the jar file in your project's Web-INF/lib.
 
Akhilesh Trivedi
Ranch Hand
Posts: 1599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aneek, has this anything to do with SCJP/OCPJP?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic