ITRI HBase 進階課程
HBase 範例
範例五: 刪除資料表
$ bin/hadoop jar ItriMenu.jar DropTable "ex1Table"
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 <TableName> "); return; } drop(otherArgs[0]); } }
- 執行結果
Droped the table [ex1Table]
Last modified 14 years ago
Last modified on Apr 25, 2011, 3:55:30 PM