- HBase 教程
- HBase - 主页
- HBase - 概述
- HBase - 架构
- HBase - 安装
- HBase - 外壳
- HBase - 常规命令
- HBase - 管理 API
- HBase - 创建表
- HBase - 列出表
- HBase - 禁用表
- HBase - 启用表
- HBase - 描述 & 更改
- HBase - 存在
- HBase - 删除表
- HBase - 关闭
- HBase - 客户端 API
- HBase - 创建数据
- HBase - 更新数据
- HBase - 读取数据
- HBase - 删除数据
- HBase - 扫描
- HBase - 计数 & 截断
- HBase - 安全
- HBase 资源
- HBase - 问题和解答
- HBase - 快速指南
- HBase - 有用资源
HBase - 存在
使用 HBase 外壳的表存在
使用 exists 命令即可验证表是否存在。以下示例显示如何使用此命令。
hbase(main):024:0> exists 'emp' Table emp does exist 0 row(s) in 0.0750 seconds ================================================================== hbase(main):015:0> exists 'student' Table student does not exist 0 row(s) in 0.0480 seconds
使用 Java API 验证表是否存在
使用 HBaseAdmin 类的 tableExists() 方法即可验证 HBase 中表是否存在。按照以下步骤在 HBase 中验证表是否存在。
步骤 1
Instantiate the HBaseAdimn class // Instantiating configuration object Configuration conf = HBaseConfiguration.create(); // Instantiating HBaseAdmin class HBaseAdmin admin = new HBaseAdmin(conf);
步骤 2
使用 tableExists( ) 方法验证表是否存在。
以下为 Java 程序,用于使用 Java API 测试 HBase 中表是否存在。
import java.io.IOException;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.client.HBaseAdmin;
public class TableExists{
public static void main(String args[])throws IOException{
// Instantiating configuration class
Configuration conf = HBaseConfiguration.create();
// Instantiating HBaseAdmin class
HBaseAdmin admin = new HBaseAdmin(conf);
// Verifying the existance of the table
boolean bool = admin.tableExists("emp");
System.out.println( bool);
}
}
编译并执行上述程序,如下所示。
$javac TableExists.java $java TableExists
输出应如下所示
true
广告