Database Reference
In-Depth Information
Here is the code that will run for you:
package com.hi.hbase.topic.chapter2;
;
// import - see GitHub for complete source code
/**
* before running this, create '' table
*/
The following class will insert the user information into the pre-existing
users table:
public class UserInsert
{
//static String tableName = "users";
static String tableName = "users";
static String familyName = "info";
public static void main(String[] args) throws Exception
{
// open connection just once and re-user it
Configuration config = HBaseConfiguration.create();
try (HTablehtable = new HTable(config, tableName)) {
int total = 100;
long t1 = System.currentTimeMillis();
// loop to insert users value, which we are
creating
// later we will do better user simulation
for (inti=0; i< total ; i++)
{
int userid = i;
String email = "user-" + i + "@foo.com";
String phone = "555-1234";
byte [] key = Bytes.toBytes(userid);
Put put = new Put (key);
put.add(Bytes.toBytes(familyName), Bytes.toBytes("email"),
Bytes.toBytes(email)); // <-- email goes here
put.add(Bytes.toBytes(familyName), Bytes.toBytes("phone"),
Bytes.toBytes(phone)); // <-- phone goes here
htable.put(put);
}
 
Search WWH ::




Custom Search