Hbase Java API调用实例

时间:2019-04-26 10:11:48   收藏:0   阅读:141

  hbase.version使用与Hbase数据库兼容的版本

        <dependency>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase-server</artifactId>
            <version>${hbase.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase-common</artifactId>
            <version>${hbase.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.hbase</groupId>
            <artifactId>hbase-client</artifactId>
            <version>${hbase.version}</version>
            <scope>runtime</scope>
        </dependency>    
static Configuration configuration = HBaseConfiguration.create();
static {
      configuration.set("hbase.zookeeper.quorum", "localhost");
      configuration.set("hbase.zookeeper.property.clientPort", "2181");
}
private String[] getHbaseTables(Configuration configuration) {
        ArrayList<String> tables = new ArrayList<>();
        try {
            HBaseAdmin hBaseAdmin = new HBaseAdmin(configuration);
            if (hBaseAdmin != null) {
                TableName[] tableNames = hBaseAdmin.listTableNames();
                for (TableName tableName : tableNames) {
                    tables.add(tableName.getNameAsString());
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return tables.toArray(new String[tables.size()]);
    }

 

原文:https://www.cnblogs.com/mohanchen/p/10772250.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!