Create and Insert a Hbase Table data using java

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


 Create and Insert 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. Create and Insert  a Hbase Table  data using java

Class Name: HbaseCreateTable

   
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;

 

/** Insert data from Hbase in java  */

public class HbaseCreateTable {

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

                              // 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.

                              hTable.put(p);

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

 

                              // closing HTable

                              hTable.close();

 

                              // closing HTable

                              hTable.close();

                    } catch (IOException e) {

                              e.printStackTrace();

                    } 

          } 

}

 
Inserted data in HUE Browser:

Run the Program:


Search
Sub-Categories
Related Articles

Leave a Comment:
illuttild
at 2022-04-02 19:03:07
cialis femme effet Yatpzn [url=https://oscialipop.com]Cialis[/url] Levitra Filmtabletten 20mg Xujhkf <a href=https://oscialipop.com>Cialis</a> Iutqkv Cjqxku https://oscialipop.com - buying cialis online reviews Mdpvlj