开发

    • 修改 PostgreSQL 的监听地址
    1. listen_addresses = '0.0.0.0'
    • 修改信任的机器列表
    1. # IPv4 local connections:
    2. host all all 127.0.0.1/32 trust
    3. host all all 0.0.0.0/0 trust
    • 重启 PostgreSQL

    JDBC连接程序

    1. package com.sequoiadb.sample;
    2. import java.sql.*;
    3.  
    4. public class postgresql_sample {
    5. static{
    6. try {
    7. Class.forName("org.postgresql.Driver");
    8. e.printStackTrace();
    9. }
    10. }
    11. public static void main( String[] args ) throws SQLException{
    12. String pghost = "192.168.30.182";
    13. String port = "5432";
    14. String databaseName = "foo";
    15. // postgresql process is running in which user
    16. String pgUser = "sdbadmin";
    17. String url = "jdbc:postgresql://"+pghost+":"+port+"/" + databaseName;
    18. Connection conn = DriverManager.getConnection(url, pgUser, null);
    19. Statement stmt = conn.createStatement();
    20. String sql = "select * from sdb_upcase_field ";
    21. ResultSet rs = stmt.executeQuery(sql);
    22. boolean isHeaderPrint = false;
    23. while (rs.next()) {
    24. int col_num = md.getColumnCount();
    25. if (!isHeaderPrint){
    26. for (int i = 1; i <= col_num; i++) {
    27. System.out.print(md.getColumnName(i) + "|");
    28. isHeaderPrint = true;
    29. }
    30. }
    31. for (int i = 1; i <= col_num; i++) {
    32. System.out.print(rs.getString(i) + "|");
    33. }
    34. System.out.println();
    35. }
    36. stmt.close();
    37. conn.close();
    38. }
    39. }