开发

    1. 编辑 /opt/postgresql/data/postgresql.conf 文件,将

    2. 修改信任的机器列表

      改为:

      1. # IPv4 local connections:
      2. host all all 127.0.0.1/32 trust
      3. host all all 0.0.0.0/0 trust

    JDBC连接程序

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