文档中心

关于 SequoiaDB

快速入门

安装

基本操作

数据模型

SQL引擎

S3引擎

系统架构

数据库管理

连接器

驱动

参考手册

故障排除

SAC 管控中心

Web服务

版本信息

开发

修改 PostgreSQL 的连接配置

  1. 修改 PostgreSQL 的监听地址

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

    listen_addresses = 'localhost'

    改为:

    listen_addresses = '0.0.0.0'
  2. 修改信任的机器列表

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

    # IPv4 local connections:
    host  all  all  127.0.0.1/32  trust

    改为:

    # IPv4 local connections:
    host  all  all  127.0.0.1/32  trust
    host  all  all  0.0.0.0/0  trust
  3. 重启 PostgreSQL

    $ bin/pg_ctl stop -s -D pg_data/ -m fast
    $ bin/postgres -D pg_data/ >> logfile 2>&1 &

JDBC连接程序

package com.sequoiadb.sample;
import java.sql.*;

public class postgresql_sample {
    static{
        try {
            Class.forName("org.postgresql.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    public static void main( String[] args ) throws SQLException{
        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()) {
            ResultSetMetaData md = rs.getMetaData();
            int col_num = md.getColumnCount();
            if (!isHeaderPrint){
                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();
    }
}
回到顶部