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()); }
Below are the error messages.
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@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 does not match the MySQL database server version.
1. Get MySQL Database Server Version Number.
- Open System Preferences in macOS.
- Click the MySQL icon in the popup window.
- Then you can get the MySQL server version.
2. Download Matched MySQL Server JDBC Version Jar File.
- 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.
- 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>
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.
This was very helpful. Thank you