文档

创建时空表

更新时间:
一键部署

创建时空表,数据库账号使用普通账号即可,普通账号可以登录DMS进行创建。

注意: getConnection中host地址,根据自己实例情况填写。如果业务在阿里云上推荐走VPC网络地址,如果业务在外部走公共网络地址。

vpc

  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. //用户请使用自己的账号和密码
  11. conn = DriverManager.getConnection("jdbc:postgresql://ts-uf6sx115kjk117156.tsdbgaia.rds.aliyuncs.com:3242/postgres","singo", "Tsdb2gaia");
  12. stmt = conn.createStatement();
  13. String sql = "CREATE TABLE tsdb_test( uid bigint, time timestamp, speed float, position geometry(Point,4326) );" +
  14. "SELECT create_hypertable('tsdb_test', 'time', chunk_time_interval => interval '1 hour')";
  15. stmt.executeUpdate(sql);
  16. stmt.close();
  17. conn.close();
  18. } catch (Exception e) {
  19. System.err.println(e.getClass().getName() + " : " + e.getMessage());
  20. System.exit(0);
  21. }
  22. System.out.println("Create table successfully");
  23. }
  24. }
  • 本页导读 (1)
文档反馈