| | 1 | {{{ |
| | 2 | #!html |
| | 3 | <div style="text-align: center; color:#151B8D"><big style="font-weight: bold;"><big><big> |
| | 4 | ITRI HBase 進階課程 |
| | 5 | </big></big></big></div> <div style="text-align: center; color:#7E2217"><big style="font-weight: bold;"><big> |
| | 6 | HBase 範例 |
| | 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 | |
| | 21 | package itri; |
| | 22 | |
| | 23 | import java.io.IOException; |
| | 24 | |
| | 25 | import org.apache.hadoop.conf.Configuration; |
| | 26 | import org.apache.hadoop.hbase.HBaseConfiguration; |
| | 27 | import org.apache.hadoop.hbase.client.HBaseAdmin; |
| | 28 | import org.apache.hadoop.util.GenericOptionsParser; |
| | 29 | |
| | 30 | public 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 | {{{ |
| | 69 | Droped the table [ex1Table] |
| | 70 | }}} |