{{{ #!html
ITRI HBase 進階課程
HBase 範例
}}} [wiki:waue/2011/0426_4_4 上一關 < ] 第五關 [wiki:waue/2011/0426_4_6 > 下一關] = 範例五: 刪除資料表 = {{{ $ bin/hadoop jar ItriMenu.jar DropTable "ex1Table" }}} {{{ #!java package itri; 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) { // String[] argc = {"t1"};argv = argc; String[] otherArgs = new GenericOptionsParser(new Configuration(), argv) .getRemainingArgs(); if (otherArgs.length < 1) { System.out.println("DropTable "); return; } drop(otherArgs[0]); } } }}} * 執行結果 {{{ Droped the table [ex1Table] }}}