求知 文章 文库 Lib 视频 iPerson 课程 认证 咨询 工具 讲座 Model Center   Code  
会员   
要资料
 
 
 

Hbase教程
Hbase架构
Hbase安装
Hbase Shell
Hbase常用命令
Hbase Admin API
Hbase创建表
Hbase列出表
Hbase禁用表
Hbase启用表
HBase表描述和修改
HBase Exists
HBase删除表
HBase关闭
HBase客户端API
HBase创建数据
HBase更新数据
HBase读取数据
HBase删除数据
HBase扫描
HBase计数和截断
HBase安全
 
 

HBase Exists
757 次浏览
32次  

可以使用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

 


您可以捐助,支持我们的公益事业。

1元 10元 50元





认证码: 验证码,看不清楚?请点击刷新验证码 必填



757 次浏览
32次
 捐助