Ashu Ashu - 1 month ago 5x
Java Question

HBase scan api from Java

I am writing some very basic stuff in Java based Hbase client for doing scan operation on existing table which is enabled. The program is based on:

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.protobuf.generated.*;

public class FirstHBaseClient {
public static void main(String[] args) throws IOException {

Configuration config = HBaseConfiguration.create();

Connection connection = ConnectionFactory.createConnection(config);
try {

Table table = connection.getTable(TableName.valueOf("test"));
try {

Scan s = new Scan();
ResultScanner scanner = table.getScanner(s);
try {

for (Result rr =; rr != null; rr = {
// print out the row we found and the columns we were looking for
System.out.println("Found row: " + rr);

} finally {


} finally {
if (table != null) table.close();
} finally {

Compilation and execution is fine...session is getting established.
But I am not getting any results from the scan operation, why?
Eclipse console output:

15/09/17 19:37:18 INFO zookeeper.ZooKeeper: Client environment:user.dir=/root/workspace_hbase/HBaseIntro
15/09/17 19:37:18 INFO zookeeper.ZooKeeper: Initiating client connection, connectString=localhost:2181 sessionTimeout=90000 watcher=hconnection-0xea4a92b0x0, quorum=localhost:2181, baseZNode=/hbase
15/09/17 19:37:18 INFO zookeeper.ClientCnxn: Opening socket connection to server localhost/ Will not attempt to authenticate using SASL (unknown error)
15/09/17 19:37:18 INFO zookeeper.ClientCnxn: Socket connection established to localhost/, initiating session
15/09/17 19:37:18 INFO zookeeper.ClientCnxn: Session establishment complete on server localhost/, sessionid = 0x14fde0f7576000e, negotiated timeout = 40000

What I am doing wrong?
I am using Hbase - 1.1.2 version on Ubuntu Linux and running JDK1.8.x.


Pheonix is altogether different approach of data retrieval... I hope at that time of testing, test data is available!!! This below code should work.

for (Result result =; (result != null); result = {
    for(KeyValue keyValue : result.list()) {
        System.out.println("Qualifier : " + keyValue.getKeyString() + " : Value : " + Bytes.toString(keyValue.getValue()));