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) {
    ex.printStackTrace();
    System.out.println("SQL State : " + ex.getSQLState());
}

mysql jdbc 08001 could not create connection to database server

INFO: Pre-instantiating singletons in org.s[email protected]36d64342: 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 do not match the MySQL database server version.

1. Get MySQL Database Server Version Number.

  1. Open System Preferences in MacOS.
  2. Click MySQL icon in the popup window.
  3. Then you can get the MySQL server version.
    start stop configure mysql server panel

2. Download Matched MySQL Server JDBC Version Jar File.

  1. You can download MySQL JDBC jar file from 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.
    <dependency>
       <groupId>mysql</groupId>
       <artifactId>mysql-connector-java</artifactId>
       <version>8.0.12</version>
    </dependency>
(Visited 20 times, 1 visits today)
READ :   Use JDBC To Connect PostgreSQL Database

Leave a Reply

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.