代碼如下: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如下:
1 回答

zengjun89
TA貢獻1條經驗 獲得超0個贊
檢查drivers/etc/hosts 里面配置的 域名,ip是否正確
hbase檢查表數據有無問題 hbase hbck details xxtb
如果?inconsistencies detected,這個字樣出現,并且大于0個;說明表結構數據可能有問題
修復此表hbase hbck repair xxtb
如果不能修復此表,hbase shell ,進入命令行,刪除舊表,disable 'xxtb',drop 'xxtb'
再次調試應用程序
添加回答
舉報
0/150
提交
取消