Changes between Version 1 and Version 2 of waue/2010/0204-04


Ignore:
Timestamp:
Feb 3, 2010, 9:51:58 PM (14 years ago)
Author:
waue
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • waue/2010/0204-04

    v1 v2  
    44{{{
    55#!java
     6package tsmc;
     7
     8import java.io.IOException;
     9import org.apache.hadoop.hbase.HBaseConfiguration;
     10import org.apache.hadoop.hbase.client.HTable;
     11import org.apache.hadoop.hbase.client.Result;
     12import org.apache.hadoop.hbase.client.ResultScanner;
     13import org.apache.hadoop.hbase.util.Bytes;
     14
     15public 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}
    645
    746}}}