Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 260
user435421 Avatar asked May 25 '26 15:05

user435421


1 Answers

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.

like image 77
codefinger Avatar answered May 27 '26 04:05

codefinger