| 1 | {{{ |
| 2 | #!html |
| 3 | <div style="text-align: center; color:#151B8D"><big style="font-weight: bold;"><big><big> |
| 4 | HBase 進階課程 |
| 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 |
| 16 | package org.nchc.hbase; |
| 17 | |
| 18 | import java.io.IOException; |
| 19 | |
| 20 | import org.apache.hadoop.conf.Configuration; |
| 21 | import org.apache.hadoop.hbase.HBaseConfiguration; |
| 22 | import org.apache.hadoop.hbase.client.HBaseAdmin; |
| 23 | import org.apache.hadoop.util.GenericOptionsParser; |
| 24 | |
| 25 | public 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 | |