hbase中删除数据
package com.test.demo01;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
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.Delete;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
public class HbaseDelete {
static private HTable table = null;
static private Configuration conf = null;
static private Connection conn = null;
//删除单条数据数据操作
public static void deleteData() throws IOException {
//参数 行健
Delete delete=new Delete("rk001".getBytes());
//参数1 列族 参数2 列 参数3 值
delete.addColumn("zu01".getBytes(), "name".getBytes());
table.delete(delete);
}
//批量删除数据 list方法删除
public static void deleteDatas() throws IOException {
// 创建集合存放数据
List<Delete> list = new ArrayList<Delete>();
//参数 行健
Delete delete=new Delete("rk1".getBytes());
//参数1 列族 参数2 列 参数3 值
delete.addColumn("zu01".getBytes(), "age".getBytes());
list.add(delete);
Delete delete2=new Delete("rk2".getBytes());
//参数1 列族 参数2 列 参数3 值
delete2.addColumn("zu01".getBytes(), "age".getBytes());
list.add(delete2);
// 用集合批量插入数据
table.delete(list);
}
public static void main(String[] args) throws IOException {
conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "hadoop01:2181,hadoop02:2181,hadoop03:2181");
conn = ConnectionFactory.createConnection(conf);
// 获取dml的句柄
// 一个Htable对象 -- 一个表
table = (HTable) conn.getTable(TableName.valueOf("student:test_teable"));
deleteDatas();
}
}