[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

Have Questions? Post them here!
Try Out Code2care Dev Tools:


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.