0

I have an IP address 192.168.218.18 I've tried a lot of ways connecting to that server every time I'm getting a message as connection attempt failed. For security reasons I've hidden the username and password.

Code:

public static void main(String[] args) {

String url = "jdbc:postgresql://192.168.218.18:5432/manikanta?user=*****&password=*****&ssl=true";
        try {

            Connection conn = DriverManager.getConnection(url);

            System.out.println("connection established");
        } catch (SQLException e) {
            System.out.println(e.getMessage());
        }
    }
}

Exceptions i got

org.postgresql.util.PSQLException: The connection attempt failed. at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:292) at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49) at org.postgresql.jdbc.PgConnection.(PgConnection.java:211) at org.postgresql.Driver.makeConnection(Driver.java:458) at org.postgresql.Driver.connect(Driver.java:260) at java.sql.DriverManager.getConnection(Unknown Source) at java.sql.DriverManager.getConnection(Unknown Source) at com.inno.demo.ConnectionJDBC.main(ConnectionJDBC.java:17) Caused by: java.net.SocketTimeoutException: connect timed out at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) at java.net.AbstractPlainSocketImpl.connect(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at org.postgresql.core.PGStream.(PGStream.java:75) at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:91) at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:192) ... 7 more

4
  • Have you verified the ping status to the above mentioned IP address? Commented Dec 17, 2019 at 10:45
  • "Ping failed". This message i'm getting even though i provided the correct details. Commented Dec 17, 2019 at 12:16
  • Please post the full exception stacktrace. Commented Dec 17, 2019 at 12:36
  • yeah i've updated the question please check Commented Dec 17, 2019 at 12:55

2 Answers 2

1

You should be passing the user and password separately, not as part of the URL:

public static void main(String[] args) {

    String url = "jdbc:postgresql://192.168.218.18:5432/v";
    String user = "****";
    String password = "*****";

    try (Connection con = DriverManager.getConnection(url, user, password);

        System.out.println("connection established");

    } catch (SQLException e) {

        System.out.println(e.getMessage());
    }
}

See: http://zetcode.com/java/postgresql/

Sign up to request clarification or add additional context in comments.

1 Comment

Still getting the same message "Connection attempt failed"
0

Since pinging to the IP 192.168.218.18 (I'll refer to this as target system) has failed, verify and confirm one of the following:

  • Your system is connected to the same network as the target system (i.e. Private network)
  • If you have access to the target system, try pinging your local machine's IP from that system and check if pinging is successful from there or not
  • Make sure that your/target system's firewall is configured to allow connections to each other

If you confirm these, I am sure you will at least have a basic idea of what and where it is going wrong. And with that your connection issue will get resolved.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.