java通过JDBC连接到MySQL数据库
我有一个简单的代码,需要连接到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,我需要做什么特别的事情吗? 谢谢 德拉戈斯
# 1 楼答案
使用: