开发
-
编辑 /opt/postgresql/data/postgresql.conf 文件,将
修改信任的机器列表
改为:
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all 0.0.0.0/0 trust
JDBC连接程序
package com.sequoiadb.sample;
import java.sql.*;
public class postgresql_sample {
static{
try {
Class.forName("org.postgresql.Driver");
e.printStackTrace();
}
}
String pghost = "192.168.30.182";
String port = "5432";
String databaseName = "foo";
// postgresql process is running in which user
String pgUser = "sdbadmin";
String url = "jdbc:postgresql://"+pghost+":"+port+"/" + databaseName;
Connection conn = DriverManager.getConnection(url, pgUser, null);
Statement stmt = conn.createStatement();
String sql = "select * from sdb_upcase_field ";
ResultSet rs = stmt.executeQuery(sql);
boolean isHeaderPrint = false;
while (rs.next()) {
int col_num = md.getColumnCount();
for (int i = 1; i <= col_num; i++) {
System.out.print(md.getColumnName(i) + "|");
isHeaderPrint = true;
}
}
for (int i = 1; i <= col_num; i++) {
System.out.print(rs.getString(i) + "|");
}
System.out.println();
}
stmt.close();
conn.close();
}
}