gpt4 book ai didi

java - 连接到 Postgresql 错误

转载 作者:可可西里 更新时间:2023-11-01 02:49:15 24 4
gpt4 key购买 nike

我正在尝试连接到 Postgres,这是我收到的错误消息:

[main] INFO org.hibernate.connection.DriverManagerConnectionProvider - using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost:5433/postgres
[main] INFO org.hibernate.connection.DriverManagerConnectionProvider - connection properties: {user=postgres, password=****}
[main] WARN org.hibernate.cfg.SettingsFactory - Could not obtain connection to query metadata
org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

我已经验证用户名/密码在我的 hibernate.conf 中没有问题

    <!-- Database connection settings -->
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://localhost/postgres</property>
<property name="connection.username">postgres</property>
<property name="connection.password">*******</property>

这是我的 pg_hba.conf

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
# host postgres,replication localhost 127.0.0.1/32 md5
# host postgres,replication localhost ::1/128 md5
host all all 0.0.0.0/0 md5

我在 Windows(不是 UNIX)上工作。所以请建议我如何解决这个问题。

谢谢!

最佳答案

连接 url 中的端口号在哪里。jdbc:postgresql://localhost:端口号/postgres

所以最终 url 应该根据我电脑上的数据库服务器端口

jdbc:postgresql://localhost:5432/postgres

关于java - 连接到 Postgresql 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19443930/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com