hbase java api

流程
  1. 先建立conn
  2. 连接table
  3. 创建get或put
  4. 执行相关操作
建立连接
import org.apache.hadoop.hbase.client.*;

Connection conn = null;

Configuration conf = HBaseConfiguration.create();
conf.setStrings("hbase.zookeeper.quorum", "192.168.0.1,192.168.0.2");
conf.setStrings("hbase.zookeeper.property.clientPort", "2181");
conf.setStrings("hbase.client.retries.number", "3");
conf.setStrings("hbase.rpc.timeout", "10000");
conf.setStrings("hbase.client.operation.timeout", "30000");

conn = ConnectionFactory.createConnection(conf);
获取table
Table table = null;
table = connection.getTable(TableName.valueOf("table"));
获取rowkey
String rowkey = null;
写入数据
Put put = new Put(Bytes.toBytes(rowkey));

// option
put.addColumn(Bytes.toBytes("family"), Bytes.toBytes("column"), Bytes.toBytes("value"));

table.put(put);
读取数据
Get get = new Get(Bytes.toBytes(rowkey));
Result result = table.get(get);
for (Map.Entry<byte[], byte[]> entry: result.getFamilyMap(Bytes.toBytes("family")).entrySet()) {
    System.out.println(Bytes.toBytes(entry.getKey()));
}
删除数据
Delete delete = new Delete(Bytes.toBytes(rowkey));

// option
delete.addColumn(Bytes.toBytes("family"), Bytes.toBytes("column"));

table.delete(delete);
Reference:

http://www.corejavaguru.com/bigdata/hbase-tutorial/hbase-java-client-api-examples

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值