1.插入数据
这次我们不需要去拿admin,因为我们不是管理表,而是直接对表进行操作
我们在拿到表之后如果想插入数据的话,要么插入一个put对象,要么插入一个put的list
而put是对我们需要放进的数据的封装
插入一行数据:
/**
* 插入一行数据
* @throws IOException
*/
@Test
public void testPut() throws IOException{
Table table = conn.getTable(TableName.valueOf("t_1"));
//put中的参数为行键
Put put = new Put("rk001".getBytes());
//参数依次为列族,key,value
//hbase提供了将各种数据转换为byte的方法Bytes.toBytes()
put.addColumn("f1".getBytes(), "uid".getBytes(), Bytes.toBytes(1));
put.addColumn("f1".getBytes(), "uname".getBytes(), Bytes.toBytes("zhangsan"));
put.addColumn("f1".getBytes(), "uage".getBytes(), Bytes.toBytes(18));
table.put(put);
table.close()