/**
 * Created by similarface on 16/8/17.
 */
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

public class PutExample {
    public static void main(String[] args) throws IOException{
        //创建必要的参数
        Configuration conf = HBaseConfiguration.create();
        //初始化客户端
        Connection connection=ConnectionFactory.createConnection(conf);
        Table table=connection.getTable(TableName.valueOf("testtable"));
        //对指定的列创建put对象
        Put put = new Put(Bytes.toBytes("row1"));
        put.addColumn(Bytes.toBytes("colfam1"),Bytes.toBytes("qual1"),Bytes.toBytes("val1"));
        put.addColumn(Bytes.toBytes("colfam1"),Bytes.toBytes("qual2"),Bytes.toBytes("val2"));
        table.put(put);
        //关闭表
        table.close();
        //关闭连接
        connection.close();
    }
}

  

相关文章:

  • 2021-11-08
  • 2021-10-02
  • 2022-12-23
  • 2021-07-07
  • 2021-08-07
  • 2021-12-04
猜你喜欢
  • 2021-11-13
  • 2021-10-31
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-07
相关资源
相似解决方案