全部产品
云市场
云游戏

查询数据

更新时间:2019-12-30 10:22:55

某时间段上,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. }