{{{ #!html
HBase 進階課程
程式範例練習
}}} [wiki:NCHCCloudCourse100929_4_HBEX4 上一關 < ] 第五關 [wiki:NCHCCloudCourse100929_4_HBEX6 > 下一關] = 範例五: 刪除資料表 = {{{ $ bin/hadoop jar TCRCExample.jar DropTable "ex1Table" }}} {{{ #!java package org.nchc.hbase; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.client.HBaseAdmin; import org.apache.hadoop.util.GenericOptionsParser; public class DropTable { static void drop(String tablename) { HBaseConfiguration conf = new HBaseConfiguration(); HBaseAdmin admin; try { admin = new HBaseAdmin(conf); if (admin.tableExists(tablename)) { admin.disableTable(tablename); admin.deleteTable(tablename); System.out.println("Droped the table [" + tablename + "]"); } else { System.out.println("Table [" + tablename + "] was not found!"); } } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] argv) { // eclipse only // String[] arg = {"ex1Table"}; // argv = arg; String[] otherArgs = new GenericOptionsParser(new Configuration(), argv) .getRemainingArgs(); if (otherArgs.length < 1) { System.out.println("DropTable "); return; } drop(otherArgs[0]); } } }}} * 執行結果 {{{ Droped the table [ex1Table] }}}