首先,抱歉我的英语不好。我在基地有计划和表格,我想连接到它。1) 方案名称 - 用户。2) 用户名 - root 3) 密码 - 香蕉。我使用 MySQL 的教程编写了这段代码
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class JavaNioServer {
public static void main (String [] args) {
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Connection conn = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost/user?"
+ "user=root&password=banana");
}catch (Exception ex) {
ex.printStackTrace();
return;
}
}}
但是代码抛出异常
> java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Unknown Source)
at JavaNioServer.JavaNioServer.main(JavaNioServer.java:9)
java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/user?user=root&password=88224148
at java.sql/java.sql.DriverManager.getConnection(Unknown Source)
at java.sql/java.sql.DriverManager.getConnection(Unknown Source)
at JavaNioServer.JavaNioServer.main(JavaNioServer.java:24)
我使用了标准的 java.sql 库,但我不明白我做错了什么......
ibeautiful
饮歌长啸
相关分类