package com.zhengtie.hbase;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.util.Bytes;
public class Demo3Delter {
//单行删除
public static void delete() throws IOException{
Configuration conf=ConnectHbase.getConf();
HTable table=new HTable(conf,"tt33");
Delete delete=new Delete(Bytes.toBytes("r1"));
table.delete(delete);
table.close();
ConnectHbase.closeConnectHBase();
}
//删除表
public static void deleteTable() throws IOException{
Configuration conf=ConnectHbase.getConf();
HBaseAdmin admin=new HBaseAdmin(conf);
try {
admin.disableTable("tt55");
admin.deleteTable("tt55");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ConnectHbase.closeConnectHBase();
}
//原子性
public static void checkAndDelete() throws IOException{
//获得配置对象
Configuration conf=ConnectHbase.getConf();
//创建出HTable对象
HTable table=new HTable(conf,“tt33”);
Delete delete=new Delete(Bytes.toBytes("r3"));
boolean res=table.checkAndDelete(Bytes.toBytes("r3"), Bytes.toBytes("cf1"), Bytes.toBytes("name"), null, delete);
if(res==true){
System.out.println("结果:"+res);
}else if(res==false){
System.out.println("结果:"+res);
}else{
System.out.println("失败!");
}
ConnectHbase.closeConnectHBase();
}
public static void main(String[] args) {
try {
//delete();
//deleteTable();
checkAndDelete();
} catch (IOException e) {
System.out.println(“删除失败!”);
e.printStackTrace();
}
}
}