{{{ #!html
HBase 進階課程
程式範例練習
}}} [wiki:NCHCCloudCourse100929_4_HBEX2 上一關 < ] 第三關 [wiki:NCHCCloudCourse100929_4_HBEX4 > 下一關] = 範例三: 取得 Column 的值 = {{{ $ bin/hadoop jar TCRCExample.jar GetColumn "ex1Table" "row221" "Detail" "c1" }}} {{{ #!java package org.nchc.hbase; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.util.GenericOptionsParser; public class GetColumn { static String getColumn(String tablename, String row, String family, String column) { HBaseConfiguration conf = new HBaseConfiguration(); String ret = ""; HTable table; try { table = new HTable(conf, Bytes.toBytes(tablename)); Get g = new Get(Bytes.toBytes(row)); Result rowResult = table.get(g); ret = Bytes.toString(rowResult.getValue(Bytes.toBytes(family + ":" + column))); table.close(); } catch (IOException e) { e.printStackTrace(); } return ret; } public static void main(String[] argv) { // eclipse only // String[] arg = {"ex1Table", "row221", "Detail", "c1"}; // argv = arg; String[] args = new GenericOptionsParser(new Configuration(), argv) .getRemainingArgs(); if (args.length < 4) { System.out.println("GetColumn "); return; } System.out.println(getColumn(args[0], args[1], args[2], args[3])); } } }}} * 執行結果 {{{ my value good }}}