全部产品
云市场

插入数据

更新时间:2019-04-26 14:19:45

写入point点数据。支持标准的点线面,多点、多线等。

  1. import java.sql.Connection;
  2. import java.sql.DriverManager;
  3. import java.sql.Statement;
  4. public class PostgreSQLJDBC {
  5. public static void main(String args[]) {
  6. Connection conn = null;
  7. Statement stmt = null;
  8. try{
  9. Class.forName("org.postgresql.Driver");
  10. conn = DriverManager.getConnection("jdbc:postgresql://ts-uf6sx115kjk117156.tsdbgaia.rds.aliyuncs.com:3242/postgres","singo", "Tsdb2gaia");
  11. conn.setAutoCommit(false);
  12. stmt = conn.createStatement();
  13. String sql = "INSERT INTO tsdb_test VALUES (1001, '2019-03-11 16:34:15', 1002.2, ST_SetSRID(ST_MakePoint(10.3,20.1),4326) )";
  14. stmt.executeUpdate(sql);
  15. sql = "INSERT INTO tsdb_test VALUES (1002, '2019-03-12 16:34:15', 2002.2, ST_SetSRID(ST_MakePoint(1.3,2.1),4326) )";
  16. stmt.executeUpdate(sql);
  17. sql = "INSERT INTO tsdb_test VALUES (1003, '2019-03-13 16:34:15', 3002.2, ST_SetSRID(ST_MakePoint(30.3,40.1),4326) )";
  18. stmt.executeUpdate(sql);
  19. stmt.close();
  20. conn.commit();
  21. conn.close();
  22. } catch (Exception e) {
  23. System.err.println(e.getClass().getName() + " : " + e.getMessage());
  24. System.exit(0);
  25. }
  26. System.out.println("insert data successfully");
  27. }
  28. }