zoukankan      html  css  js  c++  java
  • Hbase Java API调用实例

    • pom依赖

      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()]);
        }
  • 相关阅读:
    jdbc(插入大对象及读取大对象、存储过程)
    jdbc批量插入操作(addBatch)
    javase(Properties集合及学生对象信息录入文本中案例)
    javase模拟斗地主洗牌和发牌(54)
    javase套接字编程
    javase网络编程
    javase多线程复制
    javase文件切割及融合
    设计原则
    模板方法模式
  • 原文地址:https://www.cnblogs.com/mohanchen/p/10772250.html
Copyright © 2011-2022 走看看