public class NewHbaseUtils51 {
private static Configuration conf;
private static Connection hconnection;
static {
conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum","master.hadoop,slave1.hadoop,slave2.hadoop,slave3.hadoop,whoami,slave4.hadoop");
conf.set("hbase.zookeeper.property.clientPort", "2181");
conf.set("hbase.master", "whoami:60000");
try {
hconnection = ConnectionFactory.createConnection(conf);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Connection getConn(){
if(hconnection == null || hconnection.isClosed()){
try {
hconnection = ConnectionFactory.createConnection(conf);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return hconnection;
}
public static Table getHTable(String tableName) throws IOException{
return getConn().getTable(TableName.valueOf(tableName));
}
public static Admin getAdmin() throws IOException{
return getConn().getAdmin();
}
public static void close(){
if(hconnection != null){
try {
hconnection.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
java连接hbase
最新推荐文章于 2023-12-12 23:22:21 发布