Changes between Version 1 and Version 2 of NCHCCloudCourse100929_4_HBEX3
- Timestamp:
- Sep 28, 2010, 6:59:49 PM (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
NCHCCloudCourse100929_4_HBEX3
v1 v2 14 14 {{{ 15 15 #!java 16 16 17 package org.nchc.hbase; 17 18 … … 28 29 public class GetColumn { 29 30 30 static String getColumn(String tablename, String row, String family,31 String column) {32 HBaseConfiguration conf = new HBaseConfiguration();33 String ret = "";31 static String getColumn(String tablename, String row, String family, 32 String column) { 33 HBaseConfiguration conf = new HBaseConfiguration(); 34 String ret = ""; 34 35 35 HTable table;36 try {37 table = new HTable(conf, Bytes.toBytes(tablename));38 Get g = new Get(Bytes.toBytes(row));39 Result rowResult = table.get(g);40 ret = Bytes.toString(rowResult.getValue(Bytes.toBytes(family + ":"41 + column)));36 HTable table; 37 try { 38 table = new HTable(conf, Bytes.toBytes(tablename)); 39 Get g = new Get(Bytes.toBytes(row)); 40 Result rowResult = table.get(g); 41 ret = Bytes.toString(rowResult.getValue(Bytes.toBytes(family + ":" 42 + column))); 42 43 43 table.close();44 } catch (IOException e) {44 table.close(); 45 } catch (IOException e) { 45 46 46 e.printStackTrace();47 }47 e.printStackTrace(); 48 } 48 49 49 return ret;50 }50 return ret; 51 } 51 52 52 public static void main(String[] argv) { 53 public static void main(String[] argv) { 54 // eclipse only 55 // String[] arg = {"ex1Table", "row221", "Detail", "c1"}; 56 // argv = arg; 53 57 54 String[] args = new GenericOptionsParser(new Configuration(), argv)55 .getRemainingArgs();56 if (args.length < 4) {57 System.out.println("GetColumn <TableName> <Row> <Family> <Qualifier> ");58 return;59 }60 System.out.println(getColumn(args[0], args[1], args[2], args[3]));61 }58 String[] args = new GenericOptionsParser(new Configuration(), argv) 59 .getRemainingArgs(); 60 if (args.length < 4) { 61 System.out.println("GetColumn <TableName> <Row> <Family> <Qualifier> "); 62 return; 63 } 64 System.out.println(getColumn(args[0], args[1], args[2], args[3])); 65 } 62 66 } 63 67
