简体   繁体   English

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

[英]Can not connect to Postgres database on Azure with Java

I have created a Postgres database on Azure via following the instructions from https://docs.microsoft.com/en-us/azure/postgresql/connect-java .我按照https://docs.microsoft.com/en-us/azure/postgresql/connect-java的说明在 Azure 上创建了一个 Postgres 数据库。 Now I can connect to the database via my local PgAdmin and also from terminal with psql .现在我可以通过我的本地 PgAdmin 连接到数据库,也可以从带有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.但是,当我尝试在我的 java 代码 (java 8) 中连接 Hibernate(版本 5.4.21)时,我总是收到以下错误,没有任何解释。

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.<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

I tried different SSL mode options but no success.我尝试了不同的 SSL 模式选项,但没有成功。 I also disabled SSL from Azure side, but still no success.我还从 Azure 端禁用了 SSL,但仍然没有成功。 Can someone help me to resolve this issue?有人可以帮我解决这个问题吗?

We had the same issue with the 42.2.15 version of the driver.我们在42.2.15版本的驱动程序中遇到了同样的问题。 Try to set尝试设置

gssEncMode=disable

Read more: https://gitmemory.com/issue/pgjdbc/pgjdbc/1868/683710515阅读更多: https : //gitmemory.com/issue/pgjdbc/pgjdbc/1868/683710515

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM