Changes between Initial Version and Version 1 of NCHCCloudCourse100929_4_HBEX5


Ignore:
Timestamp:
Sep 27, 2010, 6:26:50 PM (14 years ago)
Author:
waue
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • NCHCCloudCourse100929_4_HBEX5

    v1 v1  
     1{{{
     2#!html
     3<div style="text-align: center; color:#151B8D"><big style="font-weight: bold;"><big><big>
     4HBase 進階課程
     5</big></big></big></div> <div style="text-align: center; color:#7E2217"><big style="font-weight: bold;"><big>
     6程式範例練習
     7</big></big></div>
     8}}}
     9
     10[wiki:NCHCCloudCourse100929_4_HBEX4 上一關 < ] 第五關 [wiki:NCHCCloudCourse100929_4_HBEX6 > 下一關]
     11
     12= 範例五: 刪除資料表 =
     13
     14{{{
     15#!java
     16package org.nchc.hbase;
     17
     18import java.io.IOException;
     19
     20import org.apache.hadoop.conf.Configuration;
     21import org.apache.hadoop.hbase.HBaseConfiguration;
     22import org.apache.hadoop.hbase.client.HBaseAdmin;
     23import org.apache.hadoop.util.GenericOptionsParser;
     24
     25public class DropTable {
     26
     27        static void drop(String tablename) {
     28                HBaseConfiguration conf = new HBaseConfiguration();
     29
     30                HBaseAdmin admin;
     31                try {
     32                        admin = new HBaseAdmin(conf);
     33                        if (admin.tableExists(tablename)) {
     34                                admin.disableTable(tablename);
     35                                admin.deleteTable(tablename);
     36                                System.out.println("Droped the table [" + tablename + "]");
     37                        } else {
     38                                System.out.println("Table [" + tablename + "] was not found!");
     39                        }
     40
     41                } catch (IOException e) {
     42                        e.printStackTrace();
     43                }
     44        }
     45
     46        public static void main(String[] argv) {
     47
     48                String[] otherArgs = new GenericOptionsParser(new Configuration(), argv)
     49                                .getRemainingArgs();
     50                if (otherArgs.length < 1) {
     51                        System.out.println("DropTable <TableName> ");
     52                        return;
     53                }
     54               
     55                drop(otherArgs[0]);
     56        }
     57}
     58
     59}}}
     60
     61