1、put/checkAndPut 1 package com.testdata; 2 3 import java.io.IOException; 4 import org.apache.hadoop.conf.Configuration; 5 import org.apach ...
1、put/checkAndPut
1 package com.testdata; 2 3 import java.io.IOException; 4 import org.apache.hadoop.conf.Configuration; 5 import org.apache.hadoop.hbase.HBaseConfiguration; 6 import org.apache.hadoop.hbase.client.HConnection; 7 import org.apache.hadoop.hbase.client.HConnectionManager; 8 import org.apache.hadoop.hbase.client.HTableInterface; 9 import org.apache.hadoop.hbase.client.Put;10 import org.apache.hadoop.hbase.util.Bytes; 11 12 public class TestPut {13 14 public static void main(String[] args) throws IOException {15 16 Configuration conf = HBaseConfiguration.create();17 conf.set("hbase.zookeeper.quorum","localhost");18 conf.set("hbase.zookeeper.property.clientPort","2181");19 HConnection conn = HConnectionManager.createConnection(conf);20 21 HTableInterface table = conn.getTable("testdata"); 22 Put testput = new Put(Bytes.toBytes("row1"));23 testput.add(Bytes.toBytes("cf"),Bytes.toBytes("col1"),Bytes.toBytes("E"));24 table.put(testput);25 //使用checkAndPut26 table.checkAndPut(Bytes.toBytes("row1"), Bytes.toBytes("cf"),Bytes.toBytes("col5"),Bytes.toBytes("E"),testput);27 table.close();28 conn.close();29 30 }31 32 }
原标题:hbase开发实例
关键词:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。