我正在运行一个简单的程序,它使JDBC与mysql连接。我使用的是5.0.8连接器jar (mysql驱动程序)。当我读到JDBC4服务机制时,我们不需要调用Class.forname("..")来注册驱动程序。我正在尝试没有它。
Connection conn = null;
try {
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/db"", "root", "root");
System.out.println("Is Connection closed: "+conn.isClosed());
} catch (SQLException e) {
throw new RuntimeException(
"Error occurred while getting connection because of : " + e.getLocalizedMessage(), e);`
} finally {
if (conn != null){
conn.close();
System.out.println("Is Connection closed: "+conn.isClosed());
}
}但是,当我执行此操作时,它会给出以下错误:
_No适合jdbc:mysql://localhost:3306/db的驱动程序
也尝试过用mysql-连接器-java-8.0.12.jar
发布于 2018-10-05 06:26:56
只有当驱动程序jar包含服务定义时,才能自动加载驱动程序。MySQL连接器/J5.0.8与JDBC4不兼容, not 包含自动加载驱动程序所需的服务定义(META-INF/services/java.sql.Driver)。因此,自动加载驱动程序无法使用5.0.8版本。
您将需要使用更新版本的MySQL连接器/J(如5.1.47或8.0.12)。
https://stackoverflow.com/questions/52658394
复制相似问题