Compare commits
No commits in common. "1b9be221e00f323c00f15fb5fea4cdfb2f256f67" and "15b008dc35075a21799654d68db3308ca184ce05" have entirely different histories.
1b9be221e0
...
15b008dc35
52
src/main/java/TableExist.java
Normal file
52
src/main/java/TableExist.java
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
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