public static void queryData(String tableName) throws IOException {
TableName name = TableName.valueOf(tableName);
Table table = connection.getTable(name);
Scan scan = new Scan();
scan.withStartRow(Bytes.toBytes("fa73b******"));
scan.withStopRow(Bytes.toBytes("fa73b******"));
//<rowKey,对应的行数据>
// Map<String, Object> result = new HashMap<>();
ResultScanner rs = null;
try {
rs = table.getScanner(scan);
for (Result r : rs) {
//每一行数据
Map<String, Object> columnMap = new HashMap<>();
String rowKey = null;
for (Cell cell : r.listCells()) {
if (rowKey == null) {
rowKey = Bytes.toString(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength());
}
columnMap.put(Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()), Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()));
}
if (rowKey != null) {
// result.put(rowKey, columnMap);
System.out.println(rowKey+"---"+new JSONObject(columnMap).toJSONString());
}
}
} catch (IOException e) {
System.out.println("遍历查询指定表中的所有数据失败");
e.printStackTrace();
} finally {
rs.close();
table.close();
}
}