推特 阿里云技术文档正文

查询数据_开发指南_时序时空数据库TSDB2.0_时序时空数据库TSDB

admin 阿里云技术文档 2020-02-11 181 0
阿里云服务器优惠

查询数据

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

  1. public class SelectJDBC {
  2. public static void main(String args[]) {
  3. Connection conn = null;
  4. Statement stmt = null;
  5. try{
  6. Class.forName("org.postgresql.Driver");
  7. //用户请使用自己的账号和密码
  8. conn = DriverManager.getConnection("jdbc:postgresql://139.224.168.86:5432/doc","citybrain", "Tsdb2gaia");
  9. stmt = conn.createStatement();
  10. conn.setAutoCommit(false);
  11. 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" +
  12. "st_contains('POLYGON ((0 0, 30 0, 30 60, 0 60, 0 0))', position)" ;
  13. ResultSet rs = stmt.executeQuery(sql);
  14. while ( rs.next() ) {
  15. long id = rs.getLong("uid");
  16. String time = rs.getString("time");
  17. String position = rs.getString("pos");
  18. System.out.println( "uid = " + id + ", time = " + time + ", position = " + position );
  19. System.out.println();
  20. }
  21. rs.close();
  22. stmt.close();
  23. conn.commit();
  24. conn.close();
  25. } catch (Exception e) {
  26. System.err.println(e.getClass().getName() + " : " + e.getMessage());
  27. System.exit(0);
  28. }
  29. System.out.println("select successfully");
  30. }
  31. }
版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

评论

-----