Caused by: java.net.ConnectException: Connection refused (Connection refused) at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:607) at com.mysql.cj.protocol.StandardSocketFactory.connect(StandardSocketFactory.java:153) at com.mysql.cj.protocol.a.NativeSocketConnection.connect(NativeSocketConnection.java:63) ... 9 more
If your Application is not able to connect to the Database you will get ConnectException: Connection refused while working with Java JDBC, below are a few reasons that can cause this Exception,
- The Database is down? Check connection to the database via DB Client or Console. Try doing telnet.
- Make sure you have defined the right database Hostname/IP Address in your JDBC DriverManager Connection.
- Make sure the Port is correct.
- Make sure your firewall settings are not restricting access.
- 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.
- Check that you have Internet connectivity.
Facing issues? Have Questions? Post them here! I am happy to answer!
More Posts related to Java,
- CRUD operations in Spring Boot + JDBC
- Java Check Leap Year - Programs with Code Examples
- [fix] Java JDBC ConnectException: Connection refused
- How to add hours and minutes to Java Instant
- Java Program: Random Number Generator
- Java: The value of the local variable string is not used
- How to get list of all Java versions installed on macOS
- Java SE JDBC with Prepared Statement Parameterized Select Example
- Java + Spring JDBC Template + Gradle Example
- Convert String to LocalDate in Java
- Remove Trailing zeros BigDecimal Java
- Java 8 Predicate Functional Interface isEqual() Method Example
- How to Hardcode Date in Java with Examples
- Java 8: Predicate negate() default Function Example
- Java: Collect Stream as ArrayList or LinkedList
- The Motivation Behind Generics in Java Programming
- How to Add/Subtract Days to the Current Date in Java
- Error: Can not find the tag library descriptor for
- Setting up JUnit 5 dependency with Maven Example
- Run Java Code Every Second
- How to create a tar.gz file using Java
- [Fix] java: integer number too large compilation error
- Java 8: Find the Max value in a List
- Your JBoss Application Server 7 is running However you have not yet added any users to be able to access the admin console
- Convert Java Array to ArrayList Code Example
- How to change default macOS Terminal Window size - MacOS
- [fix] URI is not registered (Settings | Languages & Frameworks | Schemas and DTDs) IntelliJ - Java
- Steps to Install Jenkins on M1/M2 Mac - MacOS
- The Date Command and its usage [Linux - Unix - macOS] - Linux
- Ubuntu: How to search for a package to install using apt in Terminal - Ubuntu
- How to deep copy a dictionary in Python - Python
- How to find version of Cargo in Rust - Rust
- How to hard reset Mac Terminal Window - MacOS