
If you are working with Database in your app using ORM or Spring JDBC/Spring Boot JPA, you may get this exception,
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
Fix/Solutions:
- 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
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!