• Register
Welcome to Kodlogs, programming questions and answer website.
0 votes
69 views

Problem:

I am getting below error while trying to run my JDBC code

exception in thread "main" java.lang.classnotfoundexception: com.mysql.jdbc.driver

code causing issue as below:

Class.forName("com.mysql.jdbc.Driver");
     Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/simple",
      "root","root");
     Statement stat=conn.createStatement();
     String sqlquery="SELECT * FROM CUST";
by (300 points)  
reopened by

1 Answer

+1 vote
 
Best answer

Possible Cause: 

It seems your Problem is related to "MySql Jdbc Driver"

Solution :

The "Class.forName("com.mysql.jdbc.Driver");" code is tring to load the driver, but it is not getting it, this is the reason you are getting: exception in thread "main" java.lang.classnotfoundexception: com.mysql.jdbc.driver.

To resolve the error please add the "MySQL jdbc driver jar" file in to your WEB-INF/lib folder from below link

http://dev.mysql.com/downloads/connector/j/

Conclusion:

To avoid getting this error please add "MySQL jdbc driver jar" file in to your WEB-INF/lib folder

by (36.1k points)  
selected by
...