code: public static List<String> getDatabases( String host, String port, String existingDb, String user, String pwd )
              throws Exception {
          if (existingDb == null) {
              existingDb = "postgres";
          }
          String url = EDb.POSTGRES.getJdbcPrefix() + host + ":" + port + "/" + existingDb;
          try (Connection connection = DriverManager.getConnection(url, user, pwd)) {
  
              String sql = "SELECT datname FROM pg_database WHERE datistemplate = false;";
  
              List<String> dbs = new ArrayList<>();
              try (Statement stmt = connection.createStatement(); ResultSet rs = stmt.executeQuery(sql)) {
                  while( rs.next() ) {
                      String dbName = rs.getString(1);
                      dbs.add(dbName);
                  }
                  return dbs;
              }
          }
      }
docs: Get the list of databases.
  
  @param host the host.
  @param port the port.
  @param existingDb an existing db to lean on. If null, "postgres" will be used.
  @param user optional user.
  @param pwd optional pwd.
  @return the list of available databases.
  @throws Exception