这里在打印时用了CellUtil.cloneFamily(cell)方法后,我们不需要自己去指定它的偏移量和长度,原因是CellUtil.cloneFamily(cell)方法中包含了()两个方法的功能,以免打印出来乱码,由于在底层,没有找准相关参数的位置,通过这个方法(即偏移量的处理)就能精准的定位。public void get3() throws IOException {//1. 创建get对象Get get = new Get(Bytes.toBytes("001"));//2. 查询数据,返回结果对象Result result = table.get(get);//3. 获取cell的扫描器CellScanner cellScanner = result.cellScanner();//4. 遍历扫描器while(cellScanner.advance()) {//5. 获取单词扫描的CellCell cell = cellScanner.current();System.out.println(new String(CellUtil.cloneRow(cell))); // 行键System.out.println(new String(CellUtil.cloneFamily(cell))); // 列簇System.out.println(new String(CellUtil.cloneQualifier(cell))); // 列名System.out.println(new String(CellUtil.cloneValue(cell))); // 列值}}
A. cell.getFamilyOffset()
B. cell.getFamilyLength()
C. cellScanner.current()
D. result.cellScanner()
查看答案
HBase提供了一套Java API来支持Java程序对HBase数据库的请求操作。HBase API由Admin和Table两大类组成:Table类提供管理功能:建表、创建列族、检查表是否存在、修改表结构、修改列族结构和删除表。Admin类提供数据操作功能:完成向HBase进行存储和检索数据,以及删除无效数据等操作,包括CRUD操作。
A. 对
B. 错
抽取工具类的好处是1、方便代码的维护2、简化代码量。
A. 对
B. 错
采用如下代码,我们可以往表中插入一条数据记录:public void put1() throws IOException {//1. 创建Put对象Put put = new Put(Bytes.toBytes("001"));//2. 添加列数据put.addColumn(Bytes.toBytes("zhaoliu_info"), Bytes.toBytes("name"), Bytes.toBytes("lixi"));//3. 插入一条记录admin.put(put);}
A. 对
B. 错
这里在打印时用了CellUtil.clone方法后,我们还需要自己去指定它的偏移量和长度,还需要加cell.getFamilyOffset(), cell.getFamilyLength()以免打印出来乱码,由于在底层,没有找准相关参数的位置,通过这两个方法(即偏移量的处理)就能精准的定位。public void get3() throws IOException {//1. 创建get对象Get get = new Get(Bytes.toBytes("001"));//2. 查询数据,返回结果对象Result result = table.get(get);//3. 获取cell的扫描器CellScanner cellScanner = result.cellScanner();//4. 遍历扫描器while(cellScanner.advance()) {//5. 获取单词扫描的CellCell cell = cellScanner.current();System.out.println(new String(CellUtil.cloneRow(cell))); // 行键System.out.println(new String(CellUtil.cloneFamily(cell))); // 列簇System.out.println(new String(CellUtil.cloneQualifier(cell))); // 列名System.out.println(new String(CellUtil.cloneValue(cell))); // 列值}}
A. 对
B. 错