5

We are planning to switch DB from Oracle to PostgreSQL. After creating tables, I am about to load actual data into PostgreSQL tables. In order to do it, I connect to db using JDBC. It gives me error like below.

Connection Failed! Check output console
org.postgresql.util.PSQLException: The connection attempt failed.
        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:275)
        at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:49)
        at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:194)
        at org.postgresql.Driver.makeConnection(Driver.java:450)
        at org.postgresql.Driver.connect(Driver.java:252)
        at java.sql.DriverManager.getConnection(DriverManager.java:664)
        at java.sql.DriverManager.getConnection(DriverManager.java:247)
        at JDBCExample.main(JDBCExample.java:31)
Caused by: java.net.SocketTimeoutException: connect timed out
        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:589)
        at org.postgresql.core.PGStream.<init>(PGStream.java:68)
        at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:144)
        ... 7 more

At first I thought that data loading may take time and could cause this kind of problem, but I tested with following JDBC connection java. It still returns same error like above.

public class JDBCExample {

        public static void main(String[] argv) {

                System.out.println("-------- PostgreSQL "
                                + "JDBC Connection Testing ------------");

                try {

                        Class.forName("org.postgresql.Driver");

                } catch (ClassNotFoundException e) {

                        System.out.println("Where is your PostgreSQL JDBC Driver? "
                                        + "Include in your library path!");
                        e.printStackTrace();
                        return;

                }

                System.out.println("PostgreSQL JDBC Driver Registered!");

                Connection connection = null;

                try {

                        connection = DriverManager.getConnection(
                                        "jdbc:postgresql://aaa.bbb.ccc.ddd:5432/test", "tom",
                                        "secret");

                } catch (SQLException e) {

                        System.out.println("Connection Failed! Check output console");
                        e.printStackTrace();
                        return;

                }
                catch (Exception e) {
                        e.printStackTrace();
                }

                if (connection != null) {
                        System.out.println("You made it, take control your database now!");
                } else {
                        System.out.println("Failed to make connection!");
                }
        }
}

In this case, what should I check first? There is some log file recording these errors in Postgresql? Is this something related with firewall? I even do not know our coporate has firewall? Could you give some guidance for this issue?

Anna Lee
  • 909
  • 1
  • 17
  • 37

0 Answers0