远程连接postgresql问题.连接不上.
连线被拒,请检查主机名称和埠号,并确定 postmaster 可以接受 TCP/IP 连线
postgres远程连接失败:
在本机上连接都没有问题,代码如下:
String strUrl = "jdbc:postgresql://127.0.0.1:5432/postgres";
String strDriver = "org.postgresql.Driver";
String user = "postgres";
String password = "1234";
try {
Class.forName(strDriver);
conn = DriverManager.getConnection(strUrl, user, password);
stmt = conn.createStatement();
} catch (Exception e) {
System.err.println("open postgresdb failed!");
}
远程连接,就失败:
String postSQLUrl = "jdbc:postgresql://10.100.112.131:5432/postgres";
String postSQLDriver = "org.postgresql.Driver";
String strUser = "postgres";
String strPassword = "1234";
try {
Class.forName(postSQLDriver).newInstance();
conn = DriverManager.getConnection(postSQLUrl,strUser, strPassword);
stmt = conn.createStatement();
} catch (Exception e) {
e.printStackTrace();
System.err.println("open postgreSQL db failed!");
}
谢谢大侠
------解决方案--------------------
# TYPE DATABASE USER CIDR-ADDRESS METHOD
host all all 0.0.0.0/0 md5