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    
    **/
    
  • 相关阅读:
    淘宝网的质量属性的六个常见属性场景
    架构漫谈读书笔记
    软件架构师的工作流程
    centos7通过docker安装mysql
    centos7下安装docker
    VMware 虚拟机下CentOS 7连接网络
    在JSP中使用el函数标签获取默认值(男女性别选项)
    ssm登录与退出
    MVC(Model -View-Controller)实例应用模式
    MVC模式
  • 原文地址:https://www.cnblogs.com/similarface/p/5798556.html
Copyright © 2011-2022 走看看