title: Connect to postgresql: FATAL: database "xxx" does not exist
body: <p>I'm trying to connect to a local PostgreSQL database using Java, but gets <code>org.postgresql.util.PSQLException: FATAL: database "xxx" does not exist</code></p>
  
  <pre class="lang-java prettyprint-override"><code>public class TestDemo {
      public static void main(String args[]) {
          Connection connection = null;
          try {
              Class.forName("org.postgresql.Driver");
              connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/xxx","postgres", "Dlsdb@123");
              connection.close();
          } catch (Exception e) {
              System.err.println(e.getClass().getName() + ": " + e.getMessage());
              System.exit(0);
          }
      }
  }
  </code></pre>
  
  <p>Database "xxx" exists. And in pgAdmin4 and <code>psql</code> it connected fine. I even used <code>python</code> and it worked fine:</p>
  
  <pre class="lang-py prettyprint-override"><code>def test():
      conn = psycopg2.connect(database="xxx", user="postgres", password="Dlsdb@123", host="127.0.0.1", port="5432")
      print "Opened database successfully"
      conn.close()
  </code></pre>
  
  <p>I've updated <code>pg_hba.conf</code> and set it to this:</p>
  
  <pre><code>host    all    all    127.0.0.1/32   trust
  </code></pre>
  
  <p>Tried <code>show ports</code> (if this helps), got <code>5432</code></p>
  
  <hr>
  
  <p><b>UPDATE</b></p>
  
  <p>Tried some answers: changing <code>localhost</code> to <code>127.0.0.1</code> >>> not working. </p>
  
  <p>And there's only one instance of postgreSQL(port 5432) is in listening...</p>
  
  <p>btw I changed the db name <code>xxx</code> to <code>postgres</code> in my codes because that's a default db(I guess?) and it should exists anyhow, but got the same error...</p>
  
  <hr>
  
  <p><b>PROBLEM SOLVED</b></p>
  
  <p>See my comment below</p>