【发布时间】:2019-10-08 03:27:32
【问题描述】:
我正在尝试建立一个到数据库的简单链接,但每次我尝试运行它时都会出现“没有合适的驱动程序错误”。我正在关注一个教程,所以我不确定为什么我的与所示示例相比不起作用。
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class google {
private static final String USERNAME = "Johns";
private static final String PASSWORD = "done11";
private static final String CONNECTOR = "jdbc:mysql://localhost/grading";
public static void main(String[] args) throws SQLException {
Connection conn = null;
try {
conn = DriverManager.getConnection(CONNECTOR, USERNAME, PASSWORD);
System.out.print("connected");
} catch (SQLException e) {
System.err.print(e);
}
finally {
if (conn != null) {
conn.close();
}
}
}
}
预期的输出是它说“已连接”,但它给出的错误是“java.sql.SQLException:没有为 jdbc:mysql://localhost/grading 找到合适的驱动程序”
【问题讨论】: