Home > Database > Mysql Tutorial > What is the difference between om.mysql.jdbc.Driver and com.mysql.cj.jdbc.Driver

What is the difference between om.mysql.jdbc.Driver and com.mysql.cj.jdbc.Driver

醉折花枝作酒筹
Release: 2021-05-21 09:19:24
forward
5993 people have browsed it

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.

What is the difference between om.mysql.jdbc.Driver and com.mysql.cj.jdbc.Driver

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

What is the difference between om.mysql.jdbc.Driver and com.mysql.cj.jdbc.Driver

Warehouse address: https://mvnrepository.com/artifact/mysql/mysql-connector-java

What is the difference between om.mysql.jdbc.Driver and com.mysql.cj.jdbc.Driver

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>
Copy after login

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=
Copy after login

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=
Copy after login

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=
Copy after login

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>
Copy after login

But your driver uses It is still com.mysql.jdbc.Driver, and an error will be reported:

Loading class &#39;com.mysql.jdbc.Driver&#39;. This is deprecated. The new 
driver class is &#39;com.mysql.cj.jdbc.Driver&#39;. 
The driver is automatically registered via the SPI 
and manual loading of the driver class is generally unnecessary.
Copy after login

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.
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template