I am getting the error java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
even though I have added the my-sql-connector
to the build path and it is also present in classpath.
I have searched other similar questions on stack overflow most of which suggests adding the jar to classpath which I have already done. What could be other possible problem ?
DBUtil.java
package util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
public class DBUtil {
public static Connection getMySqlConnection() throws Exception {
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/NotesStore", "root", "123");
//System.out.println("Connection returned from dbutil");
return con;
}
public static void cleanUp(Statement st, Connection con) {
try {
if (st != null) {
st.close();
}
if (con != null) {
con.close();
}
} catch (Exception e) {
System.out.println(e);
}
}
}
.classpath
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/java-8-oracle">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v8.5">
<attributes>
<attribute name="owner.project.facets" value="jst.web"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="lib" path="/home/diksha/Downloads/mysql-connector-java-8.0.11/mysql-connector-java-8.0.11.jar"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>