更新时间:2024-08-05 GMT+08:00

Phoenix表中插入数据

功能简介

使用Phoenix实现写数据。

代码样例

以下代码片段在com.huawei.bigdata.hbase.examples包的“PhoenixSample”类的testPut方法中。

  /**
   * Put data
   */
  public void testPut() {
    LOG.info("Entering testPut.");
    String URL = "jdbc:phoenix:" + conf.get("hbase.zookeeper.quorum");
    // Insert
    String upsertSQL =
        "UPSERT INTO TEST VALUES(1,'John','100000', TO_DATE('1980-01-01','yyyy-MM-dd'))";
    try (Connection conn = DriverManager.getConnection(url, props);
        Statement stat = conn.createStatement()){
      // Execute Update SQL
      stat.executeUpdate(upsertSQL);
      conn.commit();
      LOG.info("Put successfully.");
    } catch (Exception e) {
      LOG.error("Put failed.", e);
    }
    LOG.info("Exiting testPut.");
  }