How To Fix MySQL JDBC 08001 Database Connection Error

When you use MySQL JDBC driver to connect to MySQL database server. You may encounter bellow error messages.

try {
    Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/dev2qa?useSSL=false","test","666888");
} catch (SQLException ex) {
    System.out.println("SQL State : " + ex.getSQLState());

Below are the error messages.

INFO: Pre-instantiating singletons in defining beans [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,dataSource,userAccountDao]; root of factory hierarchy
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

And the SQL State code is 08001. The reason for this error is that your MySQL JDBC jar file version does not match the MySQL database server version.

1. Get MySQL Database Server Version Number.

  1. Open System Preferences in macOS.
  2. Click the MySQL icon in the popup window.
  3. Then you can get the MySQL server version.

2. Download Matched MySQL Server JDBC Version Jar File.

  1. You can download the MySQL JDBC jar file from the maven repository. If your MySQL server version is 8.0.12 so you should download JDBC jars version 8.0.12 or 8.
  2. If you use maven and pom.xml to manage your project dependency jar files, you should specify the JDBC jar file version in the pom.xml as below.

2 thoughts on “How To Fix MySQL JDBC 08001 Database Connection Error”

  1. This article was really helpful. Tried tons of options before reaching out here.
    Such a simple issue that costed me an entire day. Thanks for the help.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.