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()]); }