duncanportelli
duncanportelli

Reputation: 3229

PostgreSQL refusing connection

I hava a PostgreSQL database on my PC. The Postgres server is running on port 5432. When I go on another PC and type in telnet server.ip 5432, I manage to connect. However when I try to connect using Java:

connection = DriverManager.getConnection("Jdbc:postgresql:mydb://server.ip:5432/", "user", "pass");

I get the following error: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections. Can someone tell me what the problem might be?

UPDATE:

I changed the connection string to:

connection = DriverManager.getConnection("jdbc:postgresql://server.ip:5432/mydb", "user", "pass");

and now I am getting the error FATAL: no pg_hba.conf entry for host "client.ip", user "user", database "mydb", SSL off

Upvotes: 1

Views: 2085

Answers (2)

Malik Benmekki
Malik Benmekki

Reputation: 108

You need to config auth file /etc/postgresql/x.x/main/pg_hba.conf

Add these lines:

# TYPE DATABASE  USER  ADDRESS                   METHOD
host   all       all   my.pc.ip/Prefix-netmask   md5

After that restart the postgresql server:

# /etc/init.d/postgresql restart

Upvotes: 1

A.H.
A.H.

Reputation: 66283

Your JDBC connection string is wrong. The documentation says these are the allowed formats:

jdbc:postgresql:database
jdbc:postgresql://host/database
jdbc:postgresql://host:port/database

but not - as in your case:

Jdbc:postgresql:databse://host:port/

(also note the capital letter J in your string which is also not allowed)

Upvotes: 2

Related Questions