吴超老师课程--HBASE的查询手机项目
查询
1.按RowKey查询
2.按手机号码查询
3.按手机号码的区域查询
1 //查询手机13450456688的所有上网记录
2 public static void scan(String tableName) throws IOException{
3 HTable table = new HTable(getConfiguration(), tableName);
4 Scan scan = new Scan();
5 scan.setStartRow(Bytes.toBytes("13450456688:/"));
6 scan.setStopRow(Bytes.toBytes("13450456688::"));
7 ResultScanner scanner = table.getScanner(scan);
8 int i=0;
9 for (Result result : scanner) {
10 System.out.println("Scan: "+i+++" "+result);
11 }
12 }
1 //查询134号段的所有上网记录
2 public static void scanPeriod(String tableName) throws IOException{
3 HTable table = new HTable(getConfiguration(), tableName);
4 Scan scan = new Scan();
5 scan.setStartRow(Bytes.toBytes("134/"));
6 scan.setStopRow( Bytes.toBytes("134:"));
7 scan.setMaxVersions(1);
8 ResultScanner scanner = table.getScanner(scan);
9 int i=0;
10 for (Result result : scanner) {
11 System.out.println("Scan: "+i+++" "+result);
12 }
13 }
厚积薄发,行胜于言@飞鸟各投林