代码如下:
package hbase.test; import java.io.IOException; import java.util.List; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.ConnectionFactory; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.client.Table; import org.junit.Before; import org.junit.Test; public class HbaseDemo { Connection connection; Admin admin; @Before public void setUp() throws IOException { Configuration conf = HBaseConfiguration.create(); connection = ConnectionFactory.createConnection(conf); admin = connection.getAdmin(); } @Test public void queryTable() throws IOException { System.out.println("----------------------查询整表数据 START-----------------------"); Table table = connection.getTable(TableName.valueOf("nsl:t1")); System.out.println(123); ResultScanner scanner = table.getScanner(new Scan()); for (Result result : scanner) { byte[] row = result.getRow(); System.out.println("rowkey is :" + new String(row)); List<Cell> listCells = result.listCells(); for (Cell cell : listCells) { byte[] familyArray = cell.getFamilyArray(); byte[] qualifierArray = cell.getQualifierArray(); byte[] valueArray = cell.getValueArray(); System.out.println("row value is:" + new String(familyArray) + new String(qualifierArray) + new String(valueArray)); } } System.out.println("---------------查询整表数据 END-----------------"); } }
Debug如下:
zengjun89