Update a Hbase Table data using Java

Category : Hadoop | Sub Category : Apache HBase | By Prasad Bonam Last updated: 2020-10-17 15:38:49 Viewed : 438


Update 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. Update a Hbase Table  

Table Name: HbaseUpdate.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.Put;

import org.apache.hadoop.hbase.util.Bytes;

 

/**

 * Update data from Hbase in java

 *

 

 */

public class HbaseUpdate {

 

          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"));

                              /** Updating a name value here **/

                              p.add(Bytes.toBytes("cf"), Bytes.toBytes("name"), Bytes.toBytes("Krishna"));

                             

                              hTable.put(p);// updating the put Instance to the HTable.

                              System.out.println("Record updated successfully!!");

 

                              // closing HTable

                              hTable.close();

 

                    } catch (IOException e) {

                              e.printStackTrace();

                    }

 

          }

 

}

 

 

Run  above program as follows:



Search
Related Articles

Leave a Comment: