| | 6 | package tsmc; |
| | 7 | |
| | 8 | import java.io.IOException; |
| | 9 | import org.apache.hadoop.hbase.HBaseConfiguration; |
| | 10 | import org.apache.hadoop.hbase.client.HTable; |
| | 11 | import org.apache.hadoop.hbase.client.Result; |
| | 12 | import org.apache.hadoop.hbase.client.ResultScanner; |
| | 13 | import org.apache.hadoop.hbase.util.Bytes; |
| | 14 | |
| | 15 | public class ScanTable { |
| | 16 | |
| | 17 | static void ScanColumn(String tablename, String family, String column) { |
| | 18 | HBaseConfiguration conf = new HBaseConfiguration(); |
| | 19 | |
| | 20 | HTable table; |
| | 21 | try { |
| | 22 | table = new HTable(conf, Bytes.toBytes(tablename)); |
| | 23 | |
| | 24 | ResultScanner scanner = table.getScanner(Bytes.toBytes(family)); |
| | 25 | |
| | 26 | System.out.println("Scan the Table [" + tablename |
| | 27 | + "]'s Column => " + family + ":" + column); |
| | 28 | int i = 1; |
| | 29 | for (Result rowResult : scanner) { |
| | 30 | byte[] by = rowResult.getValue(Bytes.toBytes(family), Bytes |
| | 31 | .toBytes(column)); |
| | 32 | String str = Bytes.toString(by); |
| | 33 | System.out.println("row " + i + " is \"" + str + "\""); |
| | 34 | i++; |
| | 35 | } |
| | 36 | } catch (IOException e) { |
| | 37 | e.printStackTrace(); |
| | 38 | } |
| | 39 | } |
| | 40 | |
| | 41 | public static void main(String[] argv) { |
| | 42 | ScanColumn("tsmc", "Products", "P2"); |
| | 43 | } |
| | 44 | } |