读hbase的region简单程序--67

本文提供了一个使用Java API连接HBase并从指定表中读取特定行数据的示例。通过配置HBase客户端参数,如Zookeeper集群地址、超时时间和租约周期等,确保了与远程HBase集群的有效交互。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


import java.util.List;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.util.Bytes;

public class readRegion {
	public static void main(String[] args) throws Exception {
		readRegion tools = new readRegion();
	}

	@SuppressWarnings("deprecation")
	public readRegion() {
		Configuration hbase_config = HBaseConfiguration.create();
		hbase_config
				.set("hbase.zookeeper.quorum",
						"11.11.11.11");
		hbase_config.set("zookeeper.znode.parent", "/hbase");
		hbase_config.set("hbase.rpc.timeout", "180000");
		hbase_config.set("hbase.cluster.distributed", "true");
		hbase_config.set("hbase.regionserver.lease.period", "180000");
		try {
			/*HBaseAdmin admin = new HBaseAdmin(hbase_config);
			List<HRegionInfo> regions = admin.getTableRegions(" adfdinfo"
					.getBytes());
			for (HRegionInfo info : regions) {
				System.out.println(info.getEncodedName());
			}*/
			HTable table = new HTable(hbase_config, "test_inaao");
			String Row = "12321315351_20170718";
			byte[] row = Bytes.toBytes(Row);
			Get get = new Get(row);
			Result result = table.get(get);
			System.out.println(result);
		} catch (Exception e) {
		}
	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值