查询数据

某时间段上,BBOX范围查询。其它空间范围查询,可以参考后续提供的空间SQL

public class SelectJDBC {
    public static void main(String args[]) {
        Connection conn = null;
        Statement stmt = null;
        try{
            Class.forName("org.postgresql.Driver");
            //用户请使用自己的账号和密码
            conn = DriverManager.getConnection("jdbc:postgresql://139.224.XX.XX:5432/doc","citybrain", "Tsdb2gaia");

            stmt = conn.createStatement();
            conn.setAutoCommit(false);
            String sql = "SELECT uid,time,ST_AsText(position) AS pos FROM tsdb_test WHERE time > '2019-03-10 18:30:15' AND time < '2019-03-15 18:30:15' AND \n" +
                    "st_contains('POLYGON ((0 0, 30 0, 30 60, 0 60, 0 0))', position)" ;
            ResultSet rs = stmt.executeQuery(sql);
            while ( rs.next() ) {
                long id = rs.getLong("uid");
                String  time = rs.getString("time");
                String position  = rs.getString("pos");
                System.out.println( "uid = " + id + ", time = " + time + ", position = " + position );
                System.out.println();
            }

            rs.close();
            stmt.close();
            conn.commit();
            conn.close();

        } catch (Exception e) {
            System.err.println(e.getClass().getName() + " : " + e.getMessage());
            System.exit(0);
        }
        System.out.println("select successfully");
    }
}
阿里云首页 时间序列数据库 TSDB 相关技术圈