This article is participating in “Java Theme Month – Java Debug Notes Event”, see < Event link > for more details.
The error message
During the startup process, an error occurs during the database connection phase. The key error information is as follows:
Com. Mysql. JDBC. Exceptions. Jdbc4. MySQLNonTransientConnectionException: Could not create connection to the database server. The...Copy the code
Cause analysis,
The database version is inconsistent with the database driver version.
That is, the version of the database driver dependency package (mysql-connector-java) used in the application does not match that of the database.
The solution
1. Determine the database driver version and database version.
2. Adjust the two versions to match.
For example, if MySQL version is 8.0.16 and MySQL driver is mysql-connector-java5.1.25.jar, replace MySQL driver version with mysql-connector-java8.0.16.jar
In addition, the Mysql connector – Java versions download address: mvnrepository.com/artifact/my…
This section describes the mapping between the MySQL JDBC driver version and the MySQL database version. Select the corresponding JDBC driver and MySQL data version based on the following relationship.
- Connector/J 5.1 supports Mysql 4.1, Mysql 5.0, Mysql 5.1, and Mysql 6.0 alpha.
- Connector/J 5.0 supports MySQL 4.1, MySQL 5.0 Servers, distributed Transaction (XA).
- Connector/J 3.1 supports MySQL 4.1, MySQL 5.0 Servers, MySQL 5.0 except Distributed Transaction (XA) support.
- Connector/J 3.0 supports MySQL 3.x or MySQL 4.1.
MySQL
,Java
For the database driver versions, see:Dev.mysql.com/doc/connect…