I am trying to run a dynamic web project and have established database connection as well. However I am getting "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver" exception again and again when I am trying to run the following piece of code:
public class ConnectionC
{
public static Connection connectDao()
{
try
{
Connection dbconn= null;
String url = "jdbc:mysql://localhost:3306/practsql";
String user="root";
String password="tiger";
Class.forName("com.mysql.jdbc.Driver");
dbconn=DriverManager.getConnection(url, user, password);
return dbconn;
}
catch(ClassNotFoundException e)
{
System.out.println(e);
}
catch(SQLException e)
{
System.out.println(e);
}
return null;
}
public static void commitChange()
{
try
{
Connection dbconn= null;
String url = "jdbc:mysql://localhost:3306/practsql";
String user="root";
String password="tiger";
Class.forName("com.mysql.jdbc.Driver");
dbconn=DriverManager.getConnection(url, user, password);
dbconn.commit();
}
catch(ClassNotFoundException e)
{
System.out.println(e);
}
catch(SQLException e)
{
System.out.println(e);
}
}
}
I added jar file "mysql-connector-java-5.1.27-bin" also in the build path. However its showing the same error.