com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver的区别 serverTimezone设定

问题:
com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver的区别 serverTimezone设定

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

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

driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf8&useSSL=false
username=root
password=

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

driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/test?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false
username=root
password=

在设定时区的时候,如果设定serverTimezone=UTC,会比中国时间早8个小时,如果在中国,可以选择Asia/Shanghai或者Asia/Hongkong,例如:

driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/test?serverTimezone=Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false
username=root
password=

备注:

如果mysql-connector-java用的6.0以上的,如下:

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>6.0.6</version>
</dependency>

但是你的driver用的还是com.mysql.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 改为com.mysql.cj.jdbc.Driver

不推荐不使用服务器身份验证来建立SSL连接。
如果未明确设置,MySQL 5.5.45+, 5.6.26+ and 5.7.6+版本默认要求建立SSL连接。
为了符合当前不使用SSL连接的应用程序,verifyServerCertificate属性设置为’false’。
如果你不需要使用SSL连接,你需要通过设置useSSL=false来显式禁用SSL连接。
如果你需要用SSL连接,就要为服务器证书验证提供信任库,并设置useSSL=true。

SSL – Secure Sockets Layer(安全套接层)

原文地址:https://www.cnblogs.com/bestjdg/p/12239036.html

时间: 2024-10-08 10:31:43

com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver的区别 serverTimezone设定的相关文章

com.mysql.jdbc.Driver ==》 com.mysql.cj.jdbc.Driver

错误信息: SqlSession [[email protected]] was not registered for synchronization because synchronization is not active Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatical

java.lang.UnsupportedClassVersionError: com/mysql/cj/jdbc/Driver : Unsupported major.minor version 5

原因: com/mysql/cj/jdbc/Driver是6.0版本的驱动,兼容JDK8环境,不兼容JDK7环境,在基于jdk7的tomcat中编译运行会出错,在基于jdk8的tomcat中编译运行则不会出错. 解决方案: 1.jdk7+老版5.0驱动com/mysql/jdbc/Driver 2.jdk8+新版6.0驱动com/mysql/cj/jdbc/Driver 原文地址:https://www.cnblogs.com/GH0522/p/9328416.html

Loading class `com.mysql.jdbc.Driver&#39;. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver&#39;.

在连接数据库时,使用了最新版本的mysql-Connector,所以导致老版本的"com.mysql.jdbc.Drive"不可行,要改为"com.mysql.cj.jdbc.Driver" Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. 原文地址:https://www.cnblogs.com

mysql 问题 Loading class `com.mysql.jdbc.Driver&#39;. This is deprecated. The new driver class is `com.mysql.cj.jdb

异常错误: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. 这个问题 是在我整合项目过程中出现的

MyBatis Generator使用com.mysql.cj.jdbc.Driver遇到的问题

MyBatis Generator使用com.mysql.cj.jdbc.Driver Mybatis Generator 1.3.5 新建了一个decision库,并创建了一张user表 import org.apache.commons.lang3.StringUtils; import org.mybatis.generator.api.MyBatisGenerator; import org.mybatis.generator.config.*; import org.mybatis.g

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. 在网上巴拉巴拉发现,原

mysql的驱动类com.mysql.jdbc.Driver过时了,需要用com.mysql.cj.jdbc.Driver代替

springboot项目整合mybatis,配置文件如下: server: port: 8081 mybatis: config-location: classpath:mybatis/mybatis-config.xml #mybatis配置文件所在路径 type-aliases-package: com.yuanqiao.entities #所有entity别名类所在包 mapper-locations: classpath:mybatis/mapper/*.xml spring: appl

java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver

java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338) at java

解决Loading class `com.mysql.jdbc.Driver&#39;. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver&#39;.

异常: Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. 整合spring boot项目过程中出现的,用了最新的mysql 连接驱动 application-dev.properties spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone=