Updating Data

Updating Data using HBase Shell

We can update an existing cell value using the put command. To do so, just follow the same syntax and mention your new value as shown below.

put ‘table name’,’row ’,'Column family:column name',’new value’

The newly given value replaces the existing value. The following command will update the city value of the employee named ‘Ashok’ to Vijayawada.

hbase> put 'emp','row1','personal:city','Vijayawada'
0 row(s) in 0.0630 seconds
Updating Data Using Java API
package com.ashok.hbase;

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;

 * @author ashok.mariyala
public class MyInsertData {
   public static void main(String[] args) throws IOException {
      // Instantiating Configuration class
      Configuration config = HBaseConfiguration.create();

      // Instantiating HTable class
      HTable hTable = new HTable(config, "emp");

      // Instantiating Put class
      // accepts a row name.
      Put p = new Put(Bytes.toBytes("row1")); 

      //Updating a cell value
      // Saving the put Instance to the HTable.
      System.out.println("Data updated successfully ");
      // closing HTable
Updating Data
Scroll to top