del connect
This commit is contained in:
parent
2f36bb075f
commit
0dc78d8a4e
@ -1,3 +1,9 @@
|
|||||||
|
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class EmpHBaseClient {
|
public class EmpHBaseClient {
|
||||||
private Configuration conf;
|
private Configuration conf;
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
@ -95,7 +101,7 @@ public class EmpHBaseClient {
|
|||||||
// 新增查询ID 7500以上员工方法
|
// 新增查询ID 7500以上员工方法
|
||||||
public void findEmployeesWithEmpnoAbove7500() throws IOException {
|
public void findEmployeesWithEmpnoAbove7500() throws IOException {
|
||||||
Scan scan = new Scan();
|
Scan scan = new Scan();
|
||||||
SingleColumnValueFilter filter = new SingleColumnValueFilter(
|
FilterProtos.SingleColumnValueFilter filter = new SingleColumnValueFilter(
|
||||||
Bytes.toBytes("empnum"),
|
Bytes.toBytes("empnum"),
|
||||||
Bytes.toBytes("empno"),
|
Bytes.toBytes("empno"),
|
||||||
CompareFilter.CompareOp.GREATER_OR_EQUAL,
|
CompareFilter.CompareOp.GREATER_OR_EQUAL,
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
import org.apache.hadoop.conf.Configuration;
|
|
||||||
import org.apache.hadoop.hbase.client.*;
|
|
||||||
import java.io.IOException;
|
|
||||||
public class MyConnect{
|
|
||||||
public static Configuration configuration;
|
|
||||||
public static Connection connection;
|
|
||||||
public static Admin admin;
|
|
||||||
public static void main(String[] args)throws IOException{
|
|
||||||
init();
|
|
||||||
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