Database Reference
In-Depth Information
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;
public class SinglePutEx {
public static void main(String[] args) throws IOException {
// Get instance of Default Configuration
Configuration conf = HBaseConfiguration.create();
// Get table instance
HTable table = new HTable(conf, "tab1");
// Create Put with rowkey
Put put = new Put(Bytes.toBytes("row-1"));
// Add a column with value "Hello", in "cf1:greet", to the // Put.
put.add(Bytes.toBytes("cf1"), Bytes.toBytes("greet"),
Bytes.toBytes("Hello"));
// Add more column with value "John", in "cf1:person",
// to the Put.
put.add(Bytes.toBytes("cf1"), Bytes.toBytes("person"),
Bytes.toBytes("John"));
table.put(put);
table.close();
}
}
Data can be inserted into HBase for a single row or as a batch representing multiple
rows using the following method of the HTable class:
void put(List<Put> puts)
A list of Put instances can be created, as follows:
List<Put> puts = new ArrayList<Put>();
Put put1 = new Put(Bytes.toBytes("row-1"));
put1.add(Bytes.toBytes("cf1"), Bytes.toBytes("greet"),Bytes.
toBytes("Hello"));
puts.add(put1);
….
 
Search WWH ::




Custom Search