MapReduce服务 MRS-写Phoenix表:代码样例

时间:2023-11-01 16:19:45

代码样例

以下代码片段在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/devg3-mrs/mrs_07_080037.html