Postgresql connection refused from java connection class public class PostgreSQLJDBC {
    public static void main(String args[]) {
        System.out.println("looking for db connection");
        Connection c = null;
        try {
            Class.forName("org.postgresql.Driver");
            c = DriverManager //139.59.175.170 eller 127.0.0.1/32

                    .getConnection("jdbc:postgresql://178.62.33.183:5432/steinar");
        } catch (SQLException e) {
            System.out.print("sql exception thrown ");
            e.printStackTrace();
            System.err.println(e.getClass().getName()+": "+e.getMessage());
            System.exit(0);
        }
        catch (ClassNotFoundException e){
            e.printStackTrace();
        }
        System.out.println("Opened database successfully");
    }
}


So this is my simple connection class in java. My original error message complained that the ip-adress from my computer was not in the pg_hba.conf file: 

FATAL: no pg_hba.conf entry for host "ip", user "user", database "db",


All the connection profiles are set to trust. Then i added it along with my computer username, and now i get the following error message: 

Connection to 178.62.33.183:5432 refused. 
Check that the hostname and port are 
correct and that the postmaster is 
accepting TCP/IP connections.


Port and listenadresses are set to 5432 and '*' in the postgresql.conf file

# IPv4 local connections:
host    all             myUserName         myIp            trust


Line i added in my pg_hba.conf file. Every time a change this file, psql command stops working: 

psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
You are connecting using java via TCP/IP and using psql via named pipe. The database server uses pg_hba.conf configuration file for checking connections. This file, when changed, does not require the database to restart, but it should be notified for reloading it. In that file you need at least one line for psql executed locally, and one line for java connection. The line you showed starts wish host, so this is for TCP/IP connection. Before that, you might add a line for psql like local all all trust. The first all is the database name, the second one is the user name.

About the connection: your database is configured correctly, so maybe, your TCP connection is blocked by a firewall. Does you server really have that IP address, or is there any firewall that forward connection from that IP? In the former case, test your java connection from the server, in the latter check your firewall settings.