码迷,mamicode.com
首页 > 其他好文 > 详细

Hbase之更新单条数据

时间:2016-08-23 12:57:45      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
import java.io.IOException;

/**
 * 修改数据
 */
public class MutateDataSingle {
    public static void main(String[] args) throws IOException{
        Configuration configuration = HBaseConfiguration.create();
        Connection connection = ConnectionFactory.createConnection(configuration);
        //建立表的连接
        Table table = connection.getTable(TableName.valueOf("testtable"));
        //获取put实例
        Put put = new Put(Bytes.toBytes("10086"));
        put.addColumn(Bytes.toBytes("colfam1"),Bytes.toBytes("qual1"),4,Bytes.toBytes("china mobile 1"));
        put.addColumn(Bytes.toBytes("colfam1"),Bytes.toBytes("qual4"),4,Bytes.toBytes("china mobile 4"));
        //删除
        Delete delete = new Delete(Bytes.toBytes("10086"));
        delete.addColumn(Bytes.toBytes("colfam1"),Bytes.toBytes("qual1"));
        //更新实例
        RowMutations mutations = new RowMutations(Bytes.toBytes("10086"));
        mutations.add(put);
        mutations.add(delete);
        table.mutateRow(mutations);
    }
}
//olddata
/**
 10086                                           column=colfam1:qual1, timestamp=1471836722159, value=\xE4\xB8\xAD\xE5\x9B\xBD\xE7\xA7\xBB\xE5\x8A\xA8
 */
//newdata
/**
 10086                                           column=colfam1:qual1, timestamp=4, value=china mobile 1                                                                                      
 10086                                           column=colfam1:qual4, timestamp=4, value=china mobile 4    
**/

 

Hbase之更新单条数据

标签:

原文地址:http://www.cnblogs.com/similarface/p/5798556.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!