Java: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server [duplicate]
Solution 1:
The problem is the compatibility of older versions of MySQL Connector/J with MySQL 8. You need to upgrade to either MySQL Connector/J 5.1.46 or - better - 8.0.11 (or a higher version).
Solution 2:
In my case, I was using Maven Dependency to use JDBC connector. I just changed the version of dependency. This worked for me
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.46</version>
</dependency>
Add the below version and you will be fine:
<mysql.driver.version>8.0.20</mysql.driver.version>