无法远程连接到Heroku的数据库(Java)

时间:2016-10-20 12:11:22

标签: java postgresql heroku

我正在尝试远程连接到我的数据库:

connection = DriverManager.getConnection(URL);

网址格式如下(从Heroku网站复制的所有XXX值):

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

我得到了:

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

我跑了(它没有改变" SSL关闭"状态):

heroku config:set PGSSLMODE=require --app XXXXXX

甚至将其添加到旧帖子中建议的网址中(虽然我在Heroku的文档中没有看到任何内容):

sslfactory=org.postgresql.ssl.NonValidatingFactory

1 个答案:

答案 0 :(得分:1)

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.