Simple HBase class to load data

What is below is a simple java class to load the customers table we created in a previous post

import java.util.*;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.*;

public class putHbase {
  public static void main(String[] args) throws Exception {
        HTable hTable = new HTable("customers");

    byte[] cust_family = Bytes.toBytes("cust_family");
    byte[] cust_name = Bytes.toBytes("cust_name");
    byte[] cust_address = Bytes.toBytes("cust_address");
    byte[] cust_city = Bytes.toBytes("cust_city");
    byte[] cust_state = Bytes.toBytes("cust_state");
    byte[] cust_zip = Bytes.toBytes("cust_zip");
    byte[] cust_phone = Bytes.toBytes("cust_phone");

    for (int j = 1; j < 1000; j++) {
      byte[] rowId = Bytes.toBytes(Integer.toString(j));
      Put put = new Put(rowId).add(cust_family, cust_name, Bytes.toBytes("Tom Smith"));
      put.add(cust_family, cust_address, Bytes.toBytes("123 Anywhere St."));
      put.add(cust_family, cust_city, Bytes.toBytes("Columbus"));
      put.add(cust_family, cust_state, Bytes.toBytes("OH"));
      put.add(cust_family, cust_zip, Bytes.toBytes("43215"));
      put.add(cust_family, cust_phone, Bytes.toBytes("614.111.1111"));
      hTable.put(put);
    }
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.