mysql c3p0 spring-jdbc mysql-connector-java 版本

运行正常的版本和配置

mysql 版本 8.0.20,执行sql语句SELECT VERSION()可以得到。

c3p0 用的最新版,spring-jdbc用的和spring-context一样的版本,mysql-connector-java用的最新版。(2020-07-1)

jdbc.driverClass主要是为了配置c3p0数据源,如果mysql-connector-java是8.0以上,应该用com.mysql.cj.jdbc.Driver,如果是5.0,应该用com.mysql.jdbc.Driver

  <!-- https://mvnrepository.com/artifact/c3p0/c3p0 -->
  <dependency>
      <groupId>c3p0</groupId>
      <artifactId>c3p0</artifactId>
      <version>0.9.1.2</version>
  </dependency>

  <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
  <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>5.2.2.RELEASE</version>
  </dependency>

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

mysql-connector-java报错的版本

最开始mysql-connector-java用的8.0.15jdbc.driverClass=com.mysql.jdbc.Driver, 报错:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver,但是换成8.0.20再换回去又不报错了

换成mysql-connector-java5.1.39jdbc.driverClass=com.mysql.jdbc.Driver,循环报warning:

Mon Jul 13 00:55:42 CST 2020 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.

参考

Chapter 2 Connector/J Versions, and the MySQL and Java Versions They Require

Chapter 2 Connector/J Versions, and the MySQL and Java Versions They Require

There are currently two MySQL Connector/J versions available:

  • Connector/J 8.0 (formerly Connector/J 6.0; see Changes in MySQL Connector/J 8.0.7 for an explanation of the version number change) is a Type 4 pure Java JDBC 4.2 driver for the Java 8 platform. It provides compatibility with all the functionality of MySQL 5.6, 5.7, and 8.0. Connector/J 8.0 provides ease of development features, including auto-registration with the Driver Manager, standardized validity checks, categorized SQLExceptions, support for large update counts, support for local and offset date-time variants from the java.time package, support for JDBC-4.x XML processing, support for per connection client information, and support for the NCHAR, NVARCHAR and NCLOB data types.

  • Connector/J 5.1 is also a Type 4 pure Java JDBC driver that conforms to the JDBC 4.2 specification. It provides compatibility with all the functionality of MySQL 5.6, 5.7, and 8.0. Connector/J 5.1 is covered by its own manual.

The following table summarizes the Connector/J versions available, along with the compatibility information for different versions of JDBC, MySQL Server, and Java, as well as the support status for each of the Connector/J versions:

Table 2.1 Summary of Connector/J Versions

Connector/J version

JDBC version

MySQL Server version

JRE Required

JDK Required for Compilation

Status

8.0

4.2 1

5.6, 5.7, 8.0

JRE 8 or higher

JDK 8.0 or higher3

General availability. Recommended version.

5.1

3.0, 4.0, 4.1, 4.2

5.62, 5.72, 8.02

JRE 5 or higher2

JDK 5.0 AND JDK 8.0 or higher3

General availability

Notes

  • 1 Connector/J 8.0 implements JDBC 4.2. While Connector/J 8.0 works with libraries of higher JDBC versions, it returns a SQLFeatureNotSupportedException for any calls of methods supported only by JDBC 4.3 and higher,.

  • 2 JRE 8 or higher is required for Connector/J 5.1 to connect to MySQL 5.6, 5.7, and 8.0 with SSL/TLS when using some cipher suites.

  • 3 A customized JSSE provider might be required to use some later TLS versions and cipher suites when connecting to MySQL servers. For example, because Oracle's Java 8 is shipped with a JSSE implementation that only supports TLSv1.2 and lower, you need a customized JSSE implementation to use TLSv1.3 on Oracle's Java 8 platform.

Last updated

Was this helpful?