java 访问 hbase 得不到 result或者resultScanner

代码如下:

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如下:

https://img.mukewang.com/5b59323d0001aee109170285.jpg

Liu__
浏览 2557回答 1
1回答

zengjun89

检查drivers/etc/hosts 里面配置的 域名,ip是否正确hbase检查表数据有无问题 hbase hbck details xxtb如果 inconsistencies detected,这个字样出现,并且大于0个;说明表结构数据可能有问题修复此表hbase hbck repair xxtb如果不能修复此表,hbase shell ,进入命令行,删除旧表,disable 'xxtb',drop 'xxtb'再次调试应用程序
打开App,查看更多内容
随时随地看视频慕课网APP