user435421
user435421

Reputation: 927

Can not connect to Heroku's database remotely (Java)

I am trying to connect to my database remotely:

connection = DriverManager.getConnection(URL);

URL is of following format (all XXX values copied from Heroku's website):

jdbc:postgresql://XXX:XXX/XXXX?sslmode=require&user=XXX&password=XXXXX

I am getting:

org.postgresql.util.PSQLException: FATAL: no pg_hba.conf entry for host "213......, SSL off

I had run (it didn't change "SSL off" status):

heroku config:set PGSSLMODE=require --app XXXXXX

and even added this to the URL as suggested in older posts (althought I didn't see any of it in Heroku's doc):

sslfactory=org.postgresql.ssl.NonValidatingFactory

Upvotes: 3

Views: 429

Answers (1)

codefinger
codefinger

Reputation: 10338

Make sure you are using PG JDBC client 9.4 or higher. Your JDBC connection URL will need to include the URL param:

sslmode=require

For example:

jdbc:postgresql://<host>:<port>/<dbname>?sslmode=require&user=<username>&password=<password>

For more info see Heroku docs on Connecting to a database remotely.

Upvotes: 3

Related Questions