with root cause java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

淺唱寂寞╮ 提交于 2019-12-02 14:54:35

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/19800311/with-root-cause-java-lang-classnotfoundexception-com-mysql-jdbc-driver

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!