推特 阿里云技术文档正文

更新数据_开发指南_时序时空数据库TSDB2.0_时序时空数据库TSDB

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

更新数据

更新uid为1002的记录的位置信息:

  1. public class UpdateJDBC {
  2. public static void main(String args[]) {
  3. Connection conn = null;
  4. Statement stmt = null;
  5. try{
  6. Class.forName("org.postgresql.Driver");
  7. conn = DriverManager.getConnection("jdbc:postgresql://139.224.168.86:5432/doc","citybrain", "Tsdb2gaia");
  8. conn.setAutoCommit(false);
  9. stmt = conn.createStatement();
  10. String sql = "UPDATE tsdb_test set position = ST_MakePoint(12.1,23.2) WHERE uid=1002;";
  11. stmt.executeUpdate(sql);
  12. conn.commit();
  13. // 数据库默认是1s刷新
  14. Thread.sleep(2000);
  15. ResultSet rs = stmt.executeQuery( "SELECT uid, time, ST_AsText(position) AS pos FROM tsdb_test;" );
  16. while ( rs.next() ) {
  17. long id = rs.getLong("uid");
  18. String time = rs.getString("time");
  19. String position = rs.getString("pos");
  20. System.out.println( "uid = " + id + ", time = " + time + ", position = " + position );
  21. System.out.println();
  22. }
  23. rs.close();
  24. stmt.close();
  25. conn.commit();
  26. conn.close();
  27. } catch (Exception e) {
  28. System.err.println(e.getClass().getName() + " : " + e.getMessage());
  29. System.exit(0);
  30. }
  31. System.out.println("update successfully");
  32. }
  33. }
版权声明

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

评论

-----