与根本原因java.lang.ClassNotFoundException:com.mysql.jdbc.Driver [英] with root cause java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

查看:145
本文介绍了与根本原因java.lang.ClassNotFoundException:com.mysql.jdbc.Driver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将这个小代码连接到我的mysql数据库。

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

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

有人可以帮助我吗?

推荐答案

构建路径用于编译目的(假设你没有代码中包含mysql连接器jar)。

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

如果这是web应用程序,请将其添加到lib文件夹。

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

如果这是独立应用程序,请确保mysql连接器jar可用于运行时。

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

这篇关于与根本原因java.lang.ClassNotFoundException:com.mysql.jdbc.Driver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆