Scan(Read) a Hbase Table data using Java

Category : Hadoop | Sub Category : Apache HBase | By Runner Dev Last updated: 2020-10-17 21:17:29 Viewed : 167


Scan(Read) a Hbase Table  data using Java

1.        Create a maven project


Dependency : add the below dependency in pom.xml

 

  <!--
https://mvnrepository.com/artifact/org.apache.hbase/hbase-client -->

                    <dependency>

                              <groupId>org.apache.hbase</groupId>

                              <artifactId>hbase-client</artifactId>

                              <version>1.2.0</version>

                    </dependency>

  2.       Scan a Hbase Table  :

Table Name: ReadHBaseData.java
 package com.runnerdev;

 

import java.io.IOException;

 

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.HBaseConfiguration;

import org.apache.hadoop.hbase.client.HTable;

 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.client.Result;

 

/**

 * Delete data from Hbase in java *

  

 */

public class ReadHBaseData {

 

          static String hbase_host = "10.19.85.110";

          static String hbase_Port = "2191";

 

          public static void main(String[] args) {

                    try {

                              Configuration conf = HBaseConfiguration.create();

                              conf.set("hbase.zookeeper.quorum", hbase_host);

                              conf.set("hbase.zookeeper.clientPort", hbase_Port);

                              System.out.println("Conf::" + conf);

                              HTable hTable = new HTable(conf, "Employee");// Instantiating HTable class

//                           Put p = new Put(Bytes.toBytes("9"));                      

                              Scan scan = new Scan();// Instantiating the Scan class

                              scan.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("name"));// Scan the required columns

                              scan.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("location"));

                              ResultScanner scanner = hTable.getScanner(scan);// Getting the scan result

                              // Reading values from scan result

                              for (Result result = scanner.next(); result != null; result = scanner.next())

                                        System.out.println("Reuslt data : " + result);

                              scanner.close();// closing the scanner

 

                    } catch (IOException e) {

                              e.printStackTrace();

                    }

 

          }

 

} 

 Run above program as follows:


Search
Sub-Categories
Related Articles

Leave a Comment:
Mockize
at 2022-03-24 18:53:53
The USPSTF recommends screening all adults for depression and providing appropriate treatment and followup. Leqliu [url=https://oscialipop.com]tadalafil cialis[/url] The medicine person might waft or blow smoke at recipients as part of the healing ritual. Xvamzt <a href=https://oscialipop.com>Cialis</a> Rx Mex Pharmacy Siyqip Buy Amoxicillin Antibodics Online Canada https://oscialipop.com - Cialis
Mockize
at 2022-03-25 18:49:50
achat cialis generique en france [url=https://oscialipop.com]buy cialis generic online cheap[/url] Yrscha narrowing of the pyloric sphincter <a href=https://oscialipop.com>Cialis</a> Vdfsba https://oscialipop.com - cialis online Kukkqu Achat Cialis 20mg Original