wiki:waue/2010/0204-05

範例五: 刪除資料表

執行方法

測試用打包檔 tsmcHBase_100204.jar

$ /opt/hadoop/bin/hadoop jar tsmcHBase_100204.jar DropTable

程式碼

package tsmc;

import java.io.IOException;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HBaseAdmin;

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) {
    drop("testtable");
  }
}

Last modified 14 years ago Last modified on Feb 5, 2010, 12:00:13 AM