Updated on 2024-11-28 GMT+08:00

Writing Data

The data write API is the same as the native HBase API.

Below is an example of the code implementation.

Sample Code

public void testPut() {
  LOG.info("Entering testPut.");
  try(Table table = conn.getTable(tableName)) {
    List<Put> puts = new ArrayList<>();
    Arrays.stream(SPLIT.split(LemonConstants.COMMA))
      .forEach(startkey -> {
        // Instantiate a Put object.
        Put put = new Put(Bytes.toBytes(startkey + "-rowkey001"));
        put.addColumn(FAM_M, QUA_M, Bytes.toBytes("bachelor"));
        put.addColumn(FAM_N, QUA_N, Bytes.toBytes("xiaowang"));
        puts.add(put);

        Put put1 = new Put(Bytes.toBytes(startkey + "-rowkey0012"));
        put1.addColumn(FAM_M, QUA_M, Bytes.toBytes("master"));
        put1.addColumn(FAM_N, QUA_N, Bytes.toBytes("xiaoming"));
        puts.add(put1);

        // Submit a put request.
        try {
          table.put(puts);
        } catch (IOException e) {
          LOG.info("put exception", e);
        }
      });
    LOG.info("Put successfully.");
  } catch (IOException e) {
    LOG.error("Put failed ", e);
  }
  LOG.info("Exiting testPut.");
}