Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top