= 範例三: Get Column Value = == 執行方法 == [raw-attachment:wiki:NCHCCloudCourse100204:tsmcHBase_100203.jar 測試檔案 tsmcHBase_100203.jar] {{{ $ /opt/hadoop/bin/hadoop jar tsmcHBase_100203.jar tsmc.GetColumn }}} == 程式碼 == {{{ #!java package tsmc; import java.io.IOException; 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; 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) { System.out.println(getColumn("tsmc", "T01", "Detail", "Locate")); } } }}}