Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)
I have one database with me and I have successfully connect it with workbench, but whenever I tried to execute the Java code it throws an exception:

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.

Can anyone help me with this?

3 Answers

0 votes
by (26.7k points)

This exception mainly occurs due to the older versions of MySQL connector. So basically, we need to upgrade to the higher version and then it will work fine.

I hope this will help.

Want to become a Java expert? join Java Course now!!

0 votes
by (37.3k points)

The older version of MYSQL connector/J is not compatible with MYSQL 8. To resolve this issue, upgrade to the latest version of MySQL connector/J i.e 8.0.11 or newer 

To update the version of MySQL follow the steps below:

1. Download the new version of MySQL Connector/J  from the link given below: 

https://dev.mysql.com/downloads/connector/j/ 

2. Open the command prompt and  Navigate to the directory where you downloaded the ZIP File:

3. Extract the ZIP file using a tool like '7-Zip' OR 'Winrar.’

4. Locate the old JAR file in your project’s classpath or dependency directory.

5. Remove the Old Version:

6. Copy the new JAR file to the appropriate directory

7. If using a build tool like Maven or Gradle, update your pom.xml or build.gradle as needed.

8. Use your build tool commands or IDE to rebuild and redeploy your project.

0 votes
ago by (1.8k points)

The error message 

“com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server”

 shows that your java application is not able to establish a connection with MySQL database.Basically this kind of exception occurs because of the older version of MySQL connector this we can simply resolve by upgrading it to latest version after which it will work fine.

Related questions

0 votes
1 answer
asked Feb 23, 2021 in Java by Jake (7k points)
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Mar 6, 2021 in Java by Jake (7k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...