更新时间:2024-10-31 GMT+08:00
        
          
          
        
      
      
      
      
      
      
      
      
  
      
      
      
        
删除HBase表
功能简介
HBase通过org.apache.hadoop.hbase.client.Admin的deleteTable方法来删除表。
代码样例
以下代码片段在com.huawei.bigdata.hbase.examples包的“HBaseSample”类的dropTable方法中。
public void dropTable() {
    LOG.info("Entering dropTable.");
    Admin admin = null;
    try {
      admin = conn.getAdmin();
      if (admin.tableExists(tableName)) {
        // Disable the table before deleting it.
        admin.disableTable(tableName);
        // Delete table.
        admin.deleteTable(tableName);//注[1]
      }
      LOG.info("Drop table successfully.");
    } catch (IOException e) {
      LOG.error("Drop table failed " ,e);
    } finally {
      if (admin != null) {
        try {
          // Close the Admin object.
          admin.close();
        } catch (IOException e) {
          LOG.error("Close admin failed " ,e);
        }
      }
    }
    LOG.info("Exiting dropTable.");
  }
 注意事项
注[1] 只有表被disable时,才能被删除掉,所以deleteTable常与disableTable,enableTable,tableExists,isTableEnabled,isTableDisabled结合在一起使用。
   父主题: HBase数据读写样例程序