Question

I've this little code for connect my jsp to my mysql db.

 String driver = "com.mysql.jdbc.Driver";   
 Class.forName(driver);

 String url="jdbc:mysql://localhost:3306/test1";


 Connection con = DriverManager.getConnection(url, "test1", "test1");
 Statement cmd = con.createStatement();
 String query = "SELECT * FROM champions";
 ResultSet res = cmd.executeQuery(query);
 while (res.next()) {
   System.out.print(res.getString("name") + ", ");
   System.out.println(res.getString("title")); 
 }
 res.close(); // chiudere le risorse DB è obbligatorio
 cmd.close();
 con.close(); 

I've added the connector to my build path:

But i'm still get this error:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

Someone can help me?

Was it helpful?

Solution

Build path is for compilation purpose (assuming you don't have code to include mysql connector jar in package).

If this is web application, add it to lib folder.

If this is standalone application, make sure mysql connector jar available for runtime.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top