hbase删除数据

博客围绕HBase中删除数据展开,给出了相关Java代码示例,包含包导入、配置设置、连接创建等内容,展示了在HBase里进行数据删除操作的基本实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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();
}

}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值