This article will introduce to you the difference between om.mysql.jdbc.Driver and com.mysql.cj.jdbc.Driver. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
com.mysql.jdbc.Driver
is in mysql-connector-java 5,
com.mysql .cj.jdbc.Driver
is the
download address in mysql-connector-java 6: https://dev.mysql.com/downloads/connector/j/5.1.html
Warehouse address: https://mvnrepository.com/artifact/mysql/mysql-connector-java
mysql-connector- java 5
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.49</version> </dependency>
1. JDBC connection to 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 connection to Mysql6 com.mysql.cj.jdbc .Driver
, you need to specify the time zone serverTimezone:
driverClassName=com.mysql.cj.jdbc.Driver url=jdbc:mysql://localhost:3306/test?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&useSSL=false username=root password=
When setting the time zone, if you set serverTimezone=UTC, it will be 8 hours earlier than China time. If you are in China, you can choose Asia/Shanghai Or Asia/Hongkong, for example:
driverClassName=com.mysql.cj.jdbc.Driver url=jdbc:mysql://localhost:3306/test?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf8&useSSL=false username=root password=
Note:
I. If mysql-connector-java is used above 6.0, as follows:
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>6.0.6</version> </dependency>
But your driver uses It is still com.mysql.jdbc.Driver
, and an error will be reported:
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.
At this time, you need to change com.mysql.jdbc.Driver
to com .mysql.cj.jdbc.Driver
II, and a warning:
WARN: Establishing SSL connection without server’s identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn’t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false’. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
It is not recommended to establish SSL connections without server authentication.
If not explicitly set, MySQL 5.5.45, 5.6.26 and 5.7.6 versions require an SSL connection by default.
To comply with applications that do not currently use SSL connections, the verifyServerCertificate
property is set to 'false'.
If you do not need to use SSL connections, you need to explicitly disable SSL connections by setting useSSL=false
.
If you need to connect using SSL, provide a truststore for server certificate verification and set useSSL=true
.
SSL – Secure Sockets Layer
Recommended learning: php video tutorial
The above is the detailed content of What is the difference between om.mysql.jdbc.Driver and com.mysql.cj.jdbc.Driver. For more information, please follow other related articles on the PHP Chinese website!