【发布时间】:2014-10-21 02:15:42
【问题描述】:
我在连接远程机器时遇到错误,这里是 java 错误日志 -
DBConnection.getConnectionFromDB - Error Occured -- SQL EXCEPTION
org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:207)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:64)
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:136)
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:29)
at org.postgresql.jdbc3g.AbstractJdbc3gConnection.<init>(AbstractJdbc3gConnection.java:21)
at org.postgresql.jdbc4.AbstractJdbc4Connection.<init>(AbstractJdbc4Connection.java:31)
at org.postgresql.jdbc4.Jdbc4Connection.<init>(Jdbc4Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:397)
at org.postgresql.Driver.connect(Driver.java:267)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
这里是 pg_hba.conf 文件 -
# TYPE DATABASE USER ADDRESS METHOD
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 192.168.1.101/24 trust
host all all 0.0.0.0/0 trust
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#host replication postgres 127.0.0.1/32 md5
#host replication postgres ::1/128 md5
【问题讨论】:
-
服务器在运行吗?用户名/密码是否正确?
-
@ScaryWombat : 是的,postgres 服务正在运行,并且用户名密码正确。
-
@MadProgrammer :我尝试禁用防火墙,但它不起作用。我应该提供java代码吗?我想要实现的是通过可执行jar访问数据库,数据库机器分配了ip 192.168.1.101,其他机器没有分配任何ip,他们将通过DHCP获取它。
标签: java postgresql postgresql-9.2