Directly paste the code ***** @ paramzkIp * @ paramzkPort * @ paramtablename * @ paramstartRow to pass null to scan the entire table * @ paramstopRow ~ End with * @ throwsException * publicstaticvoidscanTable (StringzkIp, StringzkPort, Stringtablename, StringstartRow, Strin
Directly paste the code. * @ param zkIp * @ param zkPort * @ param tablename * @ param startRow to pass null to scan the entire table * @ param stopRow ~ End with * @ throws Exception */public static void scanTable (String zkIp, String zkPort, String tablename, String startRow, Strin
Paste Code directly
/***** @ Param zkIp * @ param zkPort * @ param tablename * @ param startRow transfers null to scan the entire table * @ param stopRow ~ End with * @ throws Exception */public static void scanTable (String zkIp, String zkPort, String tablename, String startRow, String stopRow) throws Exception {HTablePool pool; Configuration config = HBaseConfiguration. create (); config. set ("hbase. zookeeper. quorum ", zkIp); // config. set ("hbase. zookeeper. property. clientPort ", zkPort); pool = new HTablePool (config, 2); HTableInterface hbTable = null; try {hbTable = pool. g EtTable (tablename); // table name ResultScanner rs = null; Scan scan = new Scan (); // scan. addColumn (Bytes. toBytes ("cf1"), Bytes. toBytes ("qual1"); if (startRow! = Null) {// set the scan range to scan. setStartRow (Bytes. toBytes (startRow);} if (stopRow! = Null) {scan. setStopRow (Bytes. toBytes (stopRow);} rs = hbTable. getask( scan); hbTable. close (); for (Result r: rs) {// traverse by row for (KeyValue kv: r. raw () {// traverse each row's column StringBuffer sb = new StringBuffer (). append (Bytes. toString (kv. getRow ())). append ("\ t "). append (Bytes. toString (kv. getFamily ())). append ("\ t "). append (Bytes. toString (kv. getQualifier ())). append ("\ t "). append (Bytes. toString (kv. getValue (); System. out. println (sb. toString (); // kv. getRow () key // kv. getFamily () cf1 // kv. getQualifier () column name // kv. getValue () value }}catch (Exception e) {System. out. println (e. getMessage ();} finally {pool. close ();}}