zoukankan      html  css  js  c++  java
  • Hbase指定规则扫描表

    1.创建一个scan扫描对象

    2. scan对象中有setStartRow方法和setStopRow方法,分别指向开始扫描的rowkey和结束扫描的rowkey

    3.scan对象中的addColumn方法指向所要查询的列簇中的某个列

    要注意点是在指向同一列簇中的列时,要按照字典顺序指定,如果跳着指定则会出现NullPoinException(空指针异常)

     1 public void Scan() throws IOException {
     2         HTableInterface student = connection.getTable("student");
     3 
     4         Scan scan = new Scan();
     5         //指定开始扫描的rowkey和结束扫描的rowkey
     6         scan.setStartRow("1500100018".getBytes());
     7         scan.setStopRow("1500100023".getBytes());
     8         //指定扫描指定列簇和列
     9         scan.addColumn("info".getBytes(),"name".getBytes());
    10         scan.addColumn("info".getBytes(),"age".getBytes());
    11         scan.addColumn("info".getBytes(),"gender".getBytes());
    12         //扫描表
    13         ResultScanner scanner = student.getScanner(scan);
    14 
    15         Result next;
    16         while ((next = scanner.next()) != null) {
    17             print(next);
    18         }
    19     }
    20 
    21     private void print(Result result) {
    22         String id = Bytes.toString(result.getRow());
    23 
    24         String name = Bytes.toString(result.getValue("info".getBytes(),"name".getBytes()));
    25         int age = Bytes.toInt(result.getValue("info".getBytes(),"age".getBytes()));
    26         String gender = Bytes.toString(result.getValue("info".getBytes(),"gender".getBytes()));
    27         String clazz = Bytes.toString(result.getValue("info".getBytes(),"clazz".getBytes()));
    28 
    29         System.out.println(id + "	"+name + "	"+age + "	"+gender + "	"+clazz);
    30     }
  • 相关阅读:
    MySQL_02之增删改查、PHP数据库操作
    MySQL_01之MySQL数据库基础
    git SSH key生成步骤
    Angular路由的定义和使用
    angular ng-href小测试
    AngularJs 内置指令
    一些移动端浏览器的兼容性Bug
    angular之隐藏显示,CSS类和样式
    一个用于展示的网站
    git extensions stash和stash pop
  • 原文地址:https://www.cnblogs.com/zzzzrrrr/p/13073883.html
Copyright © 2011-2022 走看看