Create and Insert a Hbase Table data using java

Category : Hadoop | Sub Category : Apache HBase | By Prasad Bonam Last updated: 2020-10-17 15:31:17 Viewed : 566

 Create and Insert a Hbase Table  data using java

1. create a maven project

Dependency : add the below dependency in pom.xml


 <!-- -->








2. Create and Insert  a Hbase Table  data using java

Class Name: HbaseCreateTable

package com.runnerdev; 


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;


/** Insert data from Hbase in java  */

public class HbaseCreateTable {

          static String hbase_host = "";

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

                              // Instantiating HTable class

                              HTable hTable = new HTable(conf, "Employee");

                              // Instantiating Put class

                              // accepts a row name.

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

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


                              // adding values using add() method

                              // accepts column family name, qualifier/row name ,value

                    //       p.add(Bytes.toBytes("cf"), Bytes.toBytes("id"), Bytes.toBytes("9"));

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


                              p.add(Bytes.toBytes("cf"), Bytes.toBytes("location"), Bytes.toBytes("Bangalore"));


                              p.add(Bytes.toBytes("cf"), Bytes.toBytes("designation"), Bytes.toBytes("Architech"));


                              p.add(Bytes.toBytes("cf"), Bytes.toBytes("salary"), Bytes.toBytes("900000"));


                              // Saving the put Instance to the HTable.


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


                              // closing HTable



                              // closing HTable


                    } catch (IOException e) {





Inserted data in HUE Browser:

Run the Program:

Related Articles

Leave a Comment: