範例三: Get Column Value
執行方法
$ /opt/hadoop/bin/hadoop jar tsmcHBase_100204.jar GetColumn
程式碼
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")); } }
Last modified 15 years ago
Last modified on Feb 5, 2010, 12:00:09 AM