wiki:waue/2010/0204-03

Version 2 (modified by waue, 15 years ago) (diff)

--

範例三: Get Column Value

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"));
  }
}