HBase 客户端通过Java访问集群

来源:互联网 发布:海康视频服务器软件 编辑:程序博客网 时间:2024/06/06 03:26

Hive有客户端,HBase也有客户端咯

hBase如何通过客户端连接呢?  简单的程序帮助你连接你的Hbase,很简单,很实用。

public class App {private static  HBaseAdmin admin = null;public static Configuration configuration; public App() throws MasterNotRunningException, ZooKeeperConnectionException, IOException{configuration = HBaseConfiguration.create();         configuration.set("hbase.zookeeper.property.clientPort", "2181");         configuration.set("hbase.zookeeper.quorum", "192.168.222.128");         configuration.set("hbase.master", "192.168.222.128:60000");         System.out.println(configuration);        admin = new HBaseAdmin(configuration);      } public static void main(String[] args) throws Exception{App app = new App();app.getAllTables();}    public List getAllTables() {          List<String> tables = null;          if (admin != null) {              try {              System.out.println("here");            System.out.println(admin.isMasterRunning());                HTableDescriptor[] allTable = admin.listTables();                  System.out.println(allTable.length);                if (allTable.length > 0)                      tables = new ArrayList<String>();                  for (HTableDescriptor hTableDescriptor : allTable) {                      tables.add(hTableDescriptor.getNameAsString());                      System.out.println(hTableDescriptor.getNameAsString());                  }              } catch (IOException e) {                  e.printStackTrace();              }          }          return tables;      }  }
上面的一些配置信息都是在hbase-site.xml中存在的。

具体的,可以查看你们的配置文件。

那么连接就会成功了吗???????

执行到这里就不动了。。。。。。。。

换另一个程序,报的错误是 hostException: ubuntu

so。。。。。。

win+R: drivers /etc/hosts  添加你的host配置:   192.168.222.128  ubuntu

再次访问,就ok了

部分结果显式:

3(共3张表)
member
student
test

连接完成。


不讲大道理,不讲深操作,只教你入门。


0 0
原创粉丝点击