流程
- 先建立conn
- 连接table
- 创建get或put
- 执行相关操作
建立连接
复制代码
1
2
3
4
5
6
7
8
9
10import 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
复制代码
1
2
3Table table = null; table = connection.getTable(TableName.valueOf("table"));
获取rowkey
复制代码
1
2String rowkey = null;
写入数据
复制代码
1
2
3
4
5Put put = new Put(Bytes.toBytes(rowkey)); // option put.addColumn(Bytes.toBytes("family"), Bytes.toBytes("column"), Bytes.toBytes("value")); table.put(put);
读取数据
复制代码
1
2
3
4
5
6Get 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())); }
删除数据
复制代码
1
2
3
4
5Delete 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
最后
以上就是超帅翅膀最近收集整理的关于hbase java api的全部内容,更多相关hbase内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复