Java操作HBase

it2025-01-10  15

rowkey查询

//根据rowKey进行查询 public static User getDataByRowKey(String tableName, String rowKey,String password) throws IOException { Admin admin = connection.getAdmin(); Table table = connection.getTable(TableName.valueOf(tableName)); Get get = new Get(rowKey.getBytes()); User user = new User(); user.setName(rowKey); //先判断是否有此条数据 if(!get.isCheckExistenceOnly()){ Result result = table.get(get); Cell[] cells = result.rawCells(); for ( Cell cell : cells){ String colName = Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength()); String value = Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()); System.out.println(" ========= "+colName); System.out.println("=========" + value); if(colName.equals("pwd")){ user.setPwd(value); } if (colName.equals("email")){ user.setEmail(value); } } } return user; }
最新回复(0)