我的PC上有一个PostgreSQL数据库。 Postgres服务器在端口5432上运行。当我在另一台PC上输入并键入telnet server.ip 5432
时,我设法连接。然而,当我尝试使用Java连接:PostgreSQL拒绝连接
connection = DriverManager.getConnection("Jdbc:postgresql:mydb://server.ip:5432/", "user", "pass");
我得到以下错误:Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.
谁能告诉我这个问题可能是什么?
UPDATE:
我改变了连接字符串:
connection = DriverManager.getConnection("jdbc:postgresql://server.ip:5432/mydb", "user", "pass");
,现在我得到的错误FATAL: no pg_hba.conf entry for host "client.ip", user "user", database "mydb", SSL off
嗯。问题是,'my.pc.ip'是服务器的IP地址。但是服务器的配置文件必须包含远程客户端的IP地址。 – 2013-04-28 18:15:27
我在pg_hba.conf中添加了远程客户端IP,它工作正常。谢谢@ A.H。 – user1135357 2013-04-28 19:11:34