Changes between Initial Version and Version 1 of waue/2011/0426_4_5


Ignore:
Timestamp:
Apr 25, 2011, 3:55:30 PM (13 years ago)
Author:
waue
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • waue/2011/0426_4_5

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