Reputation: 379
i am trying to solve this problem by following all steps which is required to connect a Apache Wicket web application to MySQL database.
step1 Right Click on project -> Build Path ->Configure Build Path -> Java Build Path -> Libraries Tab -> Add external jar -> then i browse MySql-Connector-5.0.8 jar file.
step2In program i write down
public static Connection con=null;
public static Connection getConnection()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/db1", "root", "root");
}catch(ClassNotFoundException ex){ex.printStackTrace();}
catch(SQLException e){System.out.println(e);}
finally{
try
{
con.close();
}catch(Exception e){}
}
return con;
}
but still facing Error the java.lang.ClassNotFoundException: com.mysql.jdbc.Driver now what to do..I need your help
Upvotes: 0
Views: 2372
Reputation: 1
You can fix this error by deploying mysql-connector-java-5.1.25-bin.jar into your application's classpath. If you are not sure how to set CLASSPATH, follow instructions given in that article. Depending upon your build tool you can do following to fix java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Eclipse, Maven and Gradle.
Read more: http://www.java67.com/2015/07/javalangclassnotfoundexception-com.mysql.jdbc.Driver-solution.html#ixzz5jp43It2Xstrong text
Upvotes: 0
Reputation:
Copy the jar file and paste it into your project. It will run perfectively.
Upvotes: 0
Reputation: 181
Since you mention your project is a web application I assume that you also use an application server to run your application. Make sure the driver jar is also available to the server. Depending on the platform you may have to change some of the server's configuration as well.
Upvotes: 2