HBaseAdmin连接HBase客户端
1. 创建一个新的maven项目,导入org.apache.hadoop等jar包
2. 连接Hbase客户端 并查询数据。
package com.hbase;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
/**
* Created by zhaojy on 2017/4/21.
*/
public class HBaseDemo {
private static Configuration config=null;
private static HBaseAdmin admin=null;
private final static String HB_ZK_QUORUM="10.8.177.27,10.8.177.28,10.8.177.29";
private final static String HB_ZK_PORT="2181";
private static HTablePool tp = null;
static {
try {
config= HBaseConfiguration.create();
config.set("hbase.zookeeper.property.clientPort", HB_ZK_PORT);
config.set("hbase.zookeeper.quorum",HB_ZK_QUORUM);
admin = new HBaseAdmin(config);
tp = new HTablePool(config, 10);
}catch (Exception e){
e.printStackTrace();
}
}
public static HTableInterface getTable(String tableName){
return tp.getTable(tableName);
}
public static void main(String args[]){
HTableInterface table = getTable("analytics_demo");
Get get = new Get(Bytes.toBytes("domain.0"));
try {
Result result = table.get(get);
System.out.println(result.size());
System.out.println(result);
}catch (Exception e){
e.printStackTrace();
}
}
}