java - 使用eclipse连接mysql和java

标签 java mysql eclipse database-connection

我可以使用这些语句在 java 应用程序中使用 eclipse 将 mysql 与 java 连接

String unicode = "?useUnicode=yes&characterEncoding=UTF-8";
Class.forName("com.mysql.jdbc.Driver");
            con = (Connection) DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/ams-competation" + unicode,
                    username, password);

效果不错

但我的问题是当我尝试使用服务器应用程序连接到 mysql 时出现此异常

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver 我做错了什么?谢谢大家

编辑

我已经添加了 mysql-connector

最佳答案

我认为您的 web 项目中没有包含 mysql 驱动程序 jar。

将 mysql-connector-java.. jar 文件放在您的 web 项目的 lib 文件夹中

关于java - 使用eclipse连接mysql和java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11154065/

相关文章:

java - 如何从数组中确定和使用给定数量的问题?安卓工作室

java - 如何将jooq表保存为变量然后引用它

mysql - 使用 Ansible 在 Ubuntu 14.04 上自动安装 MySQL

java - 初学者 Android : ListView to affect the next class

java - 无法找到或加载主类 Eclipse

具有多个派生的 Java 泛型

java - 创建指定参数类型或其子类型的 Arraylist

java - Ant 在 centos5.11 中失败,错误为 "Failed to locateorg.apache.tools.ant.Main"

mysql - fabric-ca-server 使用 ssl 连接到 mysql

java - 在 Eclipse 中进行动态 Web 项目或 Spring MVC 开发需要哪些插件