
- 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
廣告