先创建表和列族然后才能添加数据
hbase(main):014:0> create 'nvshen','baseinfo','extrainfo'
0 row(s) in 4.3740 seconds
hbase(main):016:0> describe 'nvshen'
DESCRIPTION ENABLED
'nvshen', {NAME => 'baseinfo', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => ' true
ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VE
RSIONS => '0', TTL => '2147483647', KEEP_DELETED_CELLS => 'false', BLOCKSIZE =
> '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'},
{NAME => 'extrainfo', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0',
VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '21474836
47', KEEP_DELETED_CELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => 'false'
, BLOCKCACHE => 'true'}
1 row(s) in 0.0690 seconds
然后再进行api相关操作
@Test
public void TestInsert() throws Exception{
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "集群的主机名和zk的端口号");
HTable nvshen = new HTable(conf,"nvshen");
//用来对单个行执行添加操作
Put name = new Put(Bytes.toBytes("rk001"));
name.add(Bytes.toBytes("baseinfo"), Bytes.toBytes("name"), Bytes.toBytes("zheng"));
Put age = new Put(Bytes.toBytes("rk001"));
age.add(Bytes.toBytes("baseinfo"), Bytes.toBytes("age"), Bytes.toBytes(20));
age.add(Bytes.toBytes("baseinfo"), Bytes.toBytes("age"), Bytes.toBytes(19));
ArrayList<Put> puts = new ArrayList<>();
puts.add(age);
puts.add(name);
nvshen.put(puts);
}
查看hbase表
hbase(main):017:0> scan 'nvshen'
ROW COLUMN+CELL
rk001 column=baseinfo:age, timestamp=1493194117575, value=\x00\x00\x00\x13
rk001 column=baseinfo:name, timestamp=1493194117575, value=zheng
1 row(s) in 0.0180 seconds