代码如下: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
提交
取消