com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver的区别

调试代码时,发现错误:

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.

在网上巴拉巴拉发现,原来:

com.mysql.jdbc.Driver 是 mysql-connector-java 5中的;
com.mysql.cj.jdbc.Driver 是 mysql-connector-java 6中的。

1、JDBC连接Mysql5 com.mysql.jdbc.Driver:

spring:
# 数据库连接
datasource:
url: jdbc:mysql://192.168.1.1:3306/demo?useUnicode=true&characterEncoding=utf8&useSSL=false
username: root
password: 123456
driver-class-name: com.mysql.jdbc.Driver

2、JDBC连接Mysql6 com.mysql.jdbc.Driver,需要指定时区serverTimezone:

spring:
# 数据库连接
datasource:
url: jdbc:mysql://192.168.1.1:3306/demo?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false
#    在设定时区的时候,如果设定serverTimezone=UTC,会比中国时间早8个小时,如果在中国,可以选择Asia/Shanghai或者Asia/Hongkong,例如:
#                                           ?serverTimezone=Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver


posted @ 2019-05-14 14:15  cqrunnerxjzh  阅读(3481)  评论(0编辑  收藏  举报