[fix] MySQL cj jdbc CommunicationsException: Communications link failure

Post Banner

If you are working with Database in your app using ORM or Spring JDBC/Spring Boot JPA, you may get this exception,

Exception in thread "main" org.springframework.jdbc.CannotGetJdbcConnectionException: 
Failed to obtain JDBC Connection; nested exception is com.mysql.cj.jdbc.exceptions.CommunicationsException: 
Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. 
The driver has not received any packets from the server.

Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

  • Make sure your Database is up. Check connection to the database via DB Client or Console. Try doing telnet.
  • How you defined the right database Hostname/IP Address in your JDBC DriverManager Connection URL?
  • Have you defined the right Database server Port?
  • Make sure your firewall settings are not restricting access.
  • Make sure you have Internet connectivity.
  • Make sure the Database server if having an IP Whitelisting policy, your IP is listed.
  • If the Database Server is on Cloud (AWS/Azure/GCS), the right policies are set.
  • If Database is on Docker Container, make sure the host port is exposed and accesiible

Facing issues? Have Questions? Post them here! I am happy to answer!

Author Info:

Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.

Follow him on: X

You can also reach out to him via e-mail: rakesh@code2care.org

Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap