Hbase访问 配置信息直接写在程序中的访问方式

public class HbaseInit{

       private String QUORUM = "*****";
      private String CLIENTPORT = "2015";
      private Configuration conf = null;
      private static HConnection conn = null;

       static{
System.setProperty("HADOOP_USER_NAME", "sousuo");
}


public Map<String, String> getMapFromHbase(String tableName, String rowKey){
Map<String, String> hbaseRes = new HashMap<String, String>();
conf =  HBaseConfiguration.create();  
        conf.set("hbase.zookeeper.quorum", QUORUM);   
        conf.set("hbase.zookeeper.property.clientPort", CLIENTPORT);  
        conf.set("zookeeper.znode.parent", "/hbase"); 
        conf.set("hbase.client.retries.number", "2"); 
        conf.set("hbase.client.pause", "100"); 
        conf.set("zookeeper.recovery.retry", "3"); 
        conf.set("zookeeper.session.timeout", "1000"); 
        conf.set("zookeeper.recovery.retry.intervalmill", "200"); 
        conf.set("ipc.socket.timeout", "2000");
        conf.set("hbase.rpc.timeout", "2000");
        conf.set("hbase.client.scanner.timeout.period", "5000");
        conf.set("hbase.client.operation.timeout", "5000");
        try {
        logger.info("取表前++++++++++++++++++++++++++++++++++++++++++");
conn = HConnectionManager.createConnection(conf);
HTable table = new HTable(conf, tableName);
logger.info("取表后++++++++++++++++++++++++++++++++++++++++++");
        Get get = new Get(Bytes.toBytes(rowKey));
        Result result = table.get(get);
        for (KeyValue rowKV : result.raw()) {
            System.out.print("行名:" + new String(rowKV.getRow()) + " ");
            System.out.print("时间戳:" + rowKV.getTimestamp() + " ");
            System.out.print("列族名:" + new String(rowKV.getFamily()) + " ");
            System.out.print("列名:" + new String(rowKV.getQualifier()) + " ");
            System.out.println("值:" + new String(rowKV.getValue()));
            hbaseRes.put("*******", new String(rowKV.getValue()));
        }

} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return hbaseRes;
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值