Revert "feat: 添加 TableExist 类用于检查 HBase 表是否存在"
This reverts commit a25459eae7
.
This commit is contained in:
parent
a25459eae7
commit
ac8bc7357d
@ -1,52 +0,0 @@
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.hbase.*;
|
||||
import org.apache.hadoop.hbase.client.*;
|
||||
import java.io.IOException;
|
||||
import java.util.Scanner;
|
||||
public class TableExist{
|
||||
public static Configuration configuration;
|
||||
public static Connection connection;
|
||||
public static Admin admin;
|
||||
public static void main(String[] args)throws IOException{
|
||||
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.print("tableName:");
|
||||
String tableName = sc.next();
|
||||
init();
|
||||
|
||||
TableName tn = TableName.valueOf(tableName);
|
||||
if(admin.tableExists(tn)) {
|
||||
System.out.println("table " + tableName + " does exist!");
|
||||
} else {
|
||||
System.out.println("table " + tableName + " don't exist!");
|
||||
}
|
||||
close();
|
||||
}
|
||||
//建立连接
|
||||
public static void init(){
|
||||
//根据 hbase-site.xml文件初始化Configuration 对象
|
||||
configuration = HBaseConfiguration.create();
|
||||
try{
|
||||
//根据 Configuration对象初始化Connection 对象
|
||||
connection = ConnectionFactory.createConnection(configuration);
|
||||
//获取Admin 对象实例
|
||||
admin = connection.getAdmin();
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
System.out.println("Connect to HBase successfully!");
|
||||
}
|
||||
//关闭连接
|
||||
public static void close(){
|
||||
try{
|
||||
if(admin != null){
|
||||
admin.close();
|
||||
}
|
||||
if(null != connection){
|
||||
connection.close();
|
||||
}
|
||||
}catch (IOException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user