Note that there are some explanatory texts on larger screens.

plurals
  1. POconnection timeout when connecting to a remote postgresql database
    primarykey
    data
    text
    <p>I am facing this problem: I have a program that loops the following:</p> <ul> <li>connect to a postgresql database</li> <li>print a count number </li> <li>close the connection</li> </ul> <p>code is as follow:</p> <pre><code>int i = 0; while(true){ IConnection conn = ((ConnectionHelper)HelperFactory.getInstance().getHelper("ConnectionHelper")).getConnection("psql"); if(conn != null &amp;&amp; conn.connect()){ conn.close(); System.out.println(i++); } } </code></pre> <p>I connect to psql db by jdbc, something like this:</p> <pre><code>DriverManager.getConnection("jdbc:postgresql://" + host + ":5432/" + database, user, password); </code></pre> <p>the conn.connect() returns true if it can successfully connect to the database (tested, I can retrieve data from it)</p> <p>But i get the following result:</p> <p>0 1 2 . . . 3919 3920 3921 3922</p> <pre><code>org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:136) at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66) at org.postgresql.jdbc2.AbstractJdbc2Connection.&lt;init&gt;(AbstractJdbc2Connection.java:125) at org.postgresql.jdbc3.AbstractJdbc3Connection.&lt;init&gt;(AbstractJdbc3Connection.java:30) at org.postgresql.jdbc3g.AbstractJdbc3gConnection.&lt;init&gt;(AbstractJdbc3gConnection.java:22) at org.postgresql.jdbc4.AbstractJdbc4Connection.&lt;init&gt;(AbstractJdbc4Connection.java:30) at org.postgresql.jdbc4.Jdbc4Connection.&lt;init&gt;(Jdbc4Connection.java:24) at org.postgresql.Driver.makeConnection(Driver.java:393) at org.postgresql.Driver.connect(Driver.java:267) </code></pre> <p>at the last loop the program stuck at trying to connect to psql til timeout. Any help?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload