import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import java.io.IOException;
public class UDB {
public static Connection getConnection() throws IOException {
System.out.println("weishenme");
Configuration configuration = HBaseConfiguration.create();
System.out.println("dingbuhzu");
configuration.set("hbase.zookeeper.quorum","hadoop102,hadoop103,hadoop104");
Connection connection = ConnectionFactory.createConnection(configuration);
return connection;
}
//关闭连接
public static void close(Connection connection){
if(connection!=null){
try {
connection.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
通过这样的函数获取hbase的连接,然后作为对象给操作函数进行调用。