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
- 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!
More Posts related to Java,
- Java JDBC Connection with Database using SSL (https) URL
- [Solution] IntelliJ: Cannot find declaration to go to, Nothing here, Java file outside of source root Errors
- Java get day of the week as an int using DayOfWeek
- Your JBoss Application Server 7 is running However you have not yet added any users to be able to access the admin console
- Convert Instant timestamp into LocalDateTime Java Code Example
- [Program] How to read three different values using Scanner in Java
- [Java] NoClassDefFoundError Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
- Read and Parse XML file using Java DOM Parser [Java Tutorial]
- Truncate table using Java JDBC Example
- Add two numbers using Java Generics
- Spring Boot Web + Thymeleaf Hello World Example in IntelliJ in 5 Easy Steps
- Java JDBC Connection with MySQL Driver in VS Code + Troubleshooting
- Java SE JDBC with Prepared Statement Parameterized Select Example
- Java JDBC Batch Update Example with PreparedStatement
- Convert String to int in Java
- How to declare and initialize Array in Java Programming
- Java 8 Predicate Functional Interface Examples
- [fix] The declared package does not match the expected package
- Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end users experience
- [Fix] java: integer number too large compilation error
- List of Java Keywords
- Tutorial Java SOAP WebServices JAS-WS with Eclipse J2EE IDE and Tomcat Server Part 1
- JBoss stuck loading JBAS015899: AS 7.1.1.Final Brontes starting
- Java java.time.Clock class code examples [Java Date Time API]
- Java monitoring and management console [jconsole]
- Emulator: Warning: restoring GLES1 context from snapshot. App may need reloading. - Android-Studio
- Fix Something went wrong 0xCAA20004 [Microsoft Teams] - Teams
- zsh: exec format error eclipse M1 Mac - zsh
- How to stop or quit cat command? - HowTos
- Add Blank Lines Between Each Lines in Notepad++ - NotepadPlusPlus
- Gradle FAILURE: Build failed with an exception - Task not found in root project - Gradle
- PHP Fatal error : Call to a member function bind_param() on a non-object - PHP