title: Postgresql JDBC connection error on Android
body: <p>I am unable to connect a PostgreSQL db on Android. Using JDBC is for development purpose only and will change to proper web service.</p>
  <ol>
  <li>I have implemented the PostgreSQL driver in build.gradle as &quot;implementation 'org.postgresql:postgresql:42.2.18.jre7&quot;</li>
  <li>My PostgreSQL database server is listening to port: 5433</li>
  <li>My computer IP in my network is 192.168.1.103</li>
  <li>And the user name and password is set correct</li>
  </ol>
  <p>The connection:</p>
  <pre><code>Connection con = null;
  try
  {
      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
      StrictMode.setThreadPolicy(policy);
  
      /* Register jdbc driver class. */
      Class.forName(&quot;org.postgresql.Driver&quot;);
  
      /* Create connection url. */
      String postgresConnUrl = &quot;jdbc:postgresql://192.168.1.103:5433/lmsdb&quot;;
  
      Properties props = new Properties();
      props.setProperty(&quot;user&quot;,&quot;postgres&quot;);
      props.setProperty(&quot;password&quot;,&quot;xxxxxxx&quot;);
      props.setProperty(&quot;ssl&quot;,&quot;false&quot;);
  
      /* Get the Connection object. */
      con = DriverManager.getConnection(postgresConnUrl, props);
  }catch(Exception ex)
  {
      ex.printStackTrace();
  }finally
  {
      return con ;
  }
  </code></pre>
  <p>When I change the IP in &quot;postgresConnUrl&quot; to 127.0.0.1 which is set in pg_hba, I get the error</p>
  <blockquote>
  <p>org.postgresql.util.PSQLException: Connection refused. Check that the
  hostname and port are correct and that the postmaster is accepting
  TCP/IP connections</p>
  </blockquote>
  <p>And when I use my computer's IP address as shown in the connection code above, the connection <code>con = DriverManager.getConnection(postgresConnUrl, props);</code> is returning null. The log shows no exception or errors, but the con is null and I am unable to trace the problem. Any directions to the problem would be helpful.</p>