MAPREDUCE服务 MRS-向Phoenix表中插入数据:代码样例

时间:2024-06-13 09:38:52

代码样例

以下代码片段在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.");
  }
support.huaweicloud.com/devg-lts-mrs/mrs_07_290035.html