【发布时间】:2014-10-26 17:13:23
【问题描述】:
我有一个简单的代码需要连接到 mysql 数据库并执行查询。
try {
conn =
DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=1234");
Statement stm = conn.createStatement();
stm.executeQuery(query);
return true;
此代码在只有一个具有 void main 的类的测试项目中就像一个魅力。 但是在我的 Web 应用程序项目中,我使用的是 apache tomcat,并且相同的代码显示错误:
SQLException: No suitable driver found for jdbc:mysql://localhost/test?user=root&password=1234
我已经添加了 jar、类路径以及所有内容。因为我使用的是tomcat,所以我需要做一些特别的事情吗? 谢谢, 龙人
【问题讨论】:
-
你忘了把
portno:3306替换为jdbc:mysql://localhost:3306/dbname?user=root&password=1234 -
照做了。