| | 6 | package tsmc; |
| | 7 | |
| | 8 | import java.io.IOException; |
| | 9 | |
| | 10 | import org.apache.hadoop.hbase.HBaseConfiguration; |
| | 11 | import org.apache.hadoop.hbase.client.Get; |
| | 12 | import org.apache.hadoop.hbase.client.HTable; |
| | 13 | import org.apache.hadoop.hbase.client.Result; |
| | 14 | import org.apache.hadoop.hbase.util.Bytes; |
| | 15 | |
| | 16 | public class GetColumn { |
| | 17 | |
| | 18 | static String getColumn(String tablename, String row, String family, |
| | 19 | String column) { |
| | 20 | HBaseConfiguration conf = new HBaseConfiguration(); |
| | 21 | String ret = ""; |
| | 22 | |
| | 23 | HTable table; |
| | 24 | try { |
| | 25 | table = new HTable(conf, Bytes.toBytes(tablename)); |
| | 26 | Get g = new Get(Bytes.toBytes(row)); |
| | 27 | Result rowResult = table.get(g); |
| | 28 | ret = Bytes.toString(rowResult.getValue(Bytes.toBytes(family + ":" |
| | 29 | + column))); |
| | 30 | |
| | 31 | table.close(); |
| | 32 | } catch (IOException e) { |
| | 33 | |
| | 34 | e.printStackTrace(); |
| | 35 | } |
| | 36 | |
| | 37 | return ret; |
| | 38 | } |
| | 39 | |
| | 40 | public static void main(String[] argv) { |
| | 41 | System.out.println(getColumn("tsmc", "T01", "Detail", "Locate")); |
| | 42 | } |
| | 43 | } |