
正文
吴超老师课程--HBASE的查询手机项目
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
查询
1.按RowKey查询
2.按手机号码查询
3.按手机号码的区域查询
//查询手机13450456688的所有上网记录
public static void scan(String tableName) throws IOException{
HTable table = new HTable(getConfiguration(), tableName);
Scan scan = new Scan();
scan.setStartRow(Bytes.toBytes("13450456688:/"));
scan.setStopRow(Bytes.toBytes("13450456688::"));
ResultScanner scanner = table.getScanner(scan);
int i=0;
for (Result result : scanner) {
System.out.println("Scan: "+i+++" "+result);
}
}
//查询134号段的所有上网记录
public static void scanPeriod(String tableName) throws IOException{
HTable table = new HTable(getConfiguration(), tableName);
Scan scan = new Scan();
scan.setStartRow(Bytes.toBytes("134/"));
scan.setStopRow( Bytes.toBytes("134:"));
scan.setMaxVersions(1);
ResultScanner scanner = table.getScanner(scan);
int i=0;
for (Result result : scanner) {
System.out.println("Scan: "+i+++" "+result);
}
}








