问题描述:
最近在hadoop集群上搭建好Hbase,用hbase shell进行增删改查操作都没有问题,但是用java API来对hbase进行操作却出现一个很奇怪的问题,就是执行java程序后没有任何反应,程序也不报错。
首先贴出我的测试代码:
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HTable;
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.util.Bytes;
public class Test {
private static Configuration conf=HBaseConfiguration.create();
static {
conf=HBaseConfiguration.create();
//注释部分如果在本地测试不需要加,要是远程连接Hbase需要制定hbase地址
// conf.set("hbase.master", "master:60000");
// conf.set("hbase.zookeeper.quorum","slave,slave2,slave3");
System.out.println(conf.get("hbase.master"));
}
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
HTable table = new HTable(conf,"test1");
Scan s = new Scan();
ResultScanner rs = table.getScanner(s);
for(Result res:rs)
{
System.out.println(res);
}
table.close();
}