无法使用Java连接到Azure上的Postgres数据库。

huangapple go评论80阅读模式
英文:

Can not connect to Postgres database on Azure with Java

问题

我已经根据 https://learn.microsoft.com/en-us/azure/postgresql/connect-java 的指示在 Azure 上创建了一个 Postgres 数据库。现在我可以通过本地的 PgAdmin 和终端上的 psql 连接到数据库。然而,当我尝试在我的 Java 代码(Java 8)中使用 Hibernate(版本 5.4.21)连接时,我总是收到如下错误,而没有任何解释:

org.postgresql.util.PSQLException: 连接尝试失败。
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:315)
    at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51)
    at org.postgresql.jdbc.PgConnection.<init>(PgConnection.java:225)
    at org.postgresql.Driver.makeConnection(Driver.java:465)
    at org.postgresql.Driver.connect(Driver.java:264)
    at java.sql.DriverManager.getConnection(DriverManager.java:664)
    at java.sql.DriverManager.getConnection(DriverManager.java:247)
    at test.ui.V9.main(V9.java:17)
Caused by: java.io.EOFException
    at org.postgresql.core.PGStream.receiveChar(PGStream.java:443)
    at org.postgresql.core.v3.ConnectionFactoryImpl.enableGSSEncrypted(ConnectionFactoryImpl.java:436)
    at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:144)
    at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:213)
    ... 7 more

我尝试了不同的 SSL 模式选项,但都没有成功。我还在 Azure 端禁用了 SSL,但仍然没有成功。有人能帮我解决这个问题吗?

英文:

I have created a Postgres database on Azure via following the instructions from https://learn.microsoft.com/en-us/azure/postgresql/connect-java. Now I can connect to the database via my local PgAdmin and also from terminal with psql. However, when I try to connect with Hibernate (version 5.4.21) in my java code (java 8) I always get the following error without any explanations.

org.postgresql.util.PSQLException: The connection attempt failed.
	at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:315)
	at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:51)
	at org.postgresql.jdbc.PgConnection.&lt;init&gt;(PgConnection.java:225)
	at org.postgresql.Driver.makeConnection(Driver.java:465)
	at org.postgresql.Driver.connect(Driver.java:264)
	at java.sql.DriverManager.getConnection(DriverManager.java:664)
	at java.sql.DriverManager.getConnection(DriverManager.java:247)
	at test.ui.V9.main(V9.java:17)
Caused by: java.io.EOFException
	at org.postgresql.core.PGStream.receiveChar(PGStream.java:443)
	at org.postgresql.core.v3.ConnectionFactoryImpl.enableGSSEncrypted(ConnectionFactoryImpl.java:436)
	at org.postgresql.core.v3.ConnectionFactoryImpl.tryConnect(ConnectionFactoryImpl.java:144)
	at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:213)
	... 7 more

I tried different SSL mode options but no success. I also disabled SSL from Azure side, but still no success. Can someone help me to resolve this issue?

答案1

得分: 2

我们在驱动程序的42.2.15版本中遇到了相同的问题。
尝试设置:

gssEncMode=disable

了解更多信息:https://gitmemory.com/issue/pgjdbc/pgjdbc/1868/683710515

英文:

We had the same issue with the 42.2.15 version of the driver.
Try to set

gssEncMode=disable

Read more: https://gitmemory.com/issue/pgjdbc/pgjdbc/1868/683710515

huangapple
  • 本文由 发表于 2020年9月23日 03:11:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/64016297.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定