解决ssm连接不上数据库,mybatis却可以单独连接上的问题
我用的8.0的mysql,把驱动改成这个就好了。。。
com.mysql.cj.jdbc.Driver
package com.mysql.jdbc;
import java.sql.SQLException;
public class Driver extends com.mysql.cj.jdbc.Driver {
public Driver() throws SQLException {
}
static {
System.err.println("Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.");
}
}
看到这句话没!
Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdbc.Driver’. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
被弃用了。
而且他这个方法里啥也没写!报错我也没看见。嘤嘤嘤。
用被继承它的新类com.mysql.cj.jdbc.Driver
package com.mysql.cj.jdbc;
import java.sql.DriverManager;
import java.sql.SQLException;
public class Driver extends NonRegisteringDriver implements java.sql.Driver {
public Driver() throws SQLException {
}
static {
try {
DriverManager.registerDriver(new Driver());
} catch (SQLException var1) {
throw new RuntimeException("Can't register driver!");
}
}
}
本文解决了使用SSM框架连接MySQL 8.0数据库失败的问题,通过更换驱动为com.mysql.cj.jdbc.Driver成功连接,同时提供了旧驱动被弃用的警告信息。
585

被折叠的 条评论
为什么被折叠?



