zoukankan      html  css  js  c++  java
  • Hbase之更新单条数据

    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=xE4xB8xADxE5x9BxBDxE7xA7xBBxE5x8AxA8
     */
    //newdata
    /**
     10086                                           column=colfam1:qual1, timestamp=4, value=china mobile 1                                                                                      
     10086                                           column=colfam1:qual4, timestamp=4, value=china mobile 4    
    **/
    
  • 相关阅读:
    mysql实战45讲
    goland破解
    主从复制系列C
    主从复制系列B
    主从复制系列A
    sshd配置文件详解
    MySQL源码 数据结构array
    MySQL源码 information_schema新增表
    MySQL5.6 基于db的并行复制
    mysql 限制并发select patch
  • 原文地址:https://www.cnblogs.com/similarface/p/5798556.html
Copyright © 2011-2022 走看看