Loading class `com.mysql.jdbc.Driver‘. This is deprecated. The new driver class is `com.mysql.cj.jdb

使用高版本mysql-connector-java注意事项

异常信息

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.
### The error may exist in com.ittze.mapper/UserMapper.xml
### The error may involve com.ittze.mapper.UserMapper.findAll
### The error occurred while executing a query
### Cause: java.sql.SQLException: The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.


原因

jar包版本过高 (如 :mysql-connector-java-6.x.x.jar版本或以上的mysql-connector-java-8.0.x.jar版本就会报此种错误)。然后,对于新版本的jar包需要 改一下驱动设置一下时区

解决方法

①改驱动:com.mysql.jdbc.Driver 改为: com.mysql.cj.jdbc.Driver
②改url路径:jdbc:mysql//localhost:3306/db1 改为:jdbc:mysql://localhost:3306/db1?serverTimezone=GMT%2B8

当然,url后面的时区改动不是定死的,还可以改其它的如:UTC(世界均衡时间),或者GMT(格林尼治时间)

jdbc:mysql://localhost:3306/demo?serverTimezone=UTC
jdbc:mysql://127.0.0.1:3306/demo?serverTimezone=UTC
jdbc:mysql://localhost:3306/demo?serverTimezone=GMT
jdbc:mysql://127.0.0.1:3306/demo?serverTimezone=GMT

再或者中国时间(北京时间)

jdbc:mysql://localhost:3306/demo?serverTimezone=GMT%2B8
jdbc:mysql://127.0.0.1:3306/demo?serverTimezone=GMT%2B8




作者留言(不重要的事情):BB一下改bug的时光,平时用Mybatis好好的,然后今天突然报错,一开始挺绝望的,但接着改着改着就更绝望了。But最后还是解决了。单纯记录一下。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值