Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to remote HBase in Java?

Tags:

hbase

I have a standlone HBase server. This is my hbase-site.xml:

<configuration>  <property>     <name>hbase.rootdir</name>     <value>file:///hbase_data</value>   </property> </configuration> 

I am trying to write a Java program to manipulate the data in the HBase.

If I run the program on the HBase server, it works fine. But I don't know how to config it for remote access.

  Configuration config = HBaseConfiguration.create();    HTable table = new HTable(config, "test");    Scan s = new Scan(); 

I have tried adding IP and Port, it doesn't work:

config.set("hbase.master", "146.169.35.28:60000") 

Can anyone tell me how to do it?

Thanks!

like image 292
leon Avatar asked Jul 07 '11 17:07

leon


People also ask

What is HBase client?

Advertisements. This chapter describes the java client API for HBase that is used to perform CRUD operations on HBase tables. HBase is written in Java and has a Java Native API. Therefore it provides programmatic access to Data Manipulation Language (DML).


1 Answers

Here's a snippet from a system we use to create an HTable we use to connect to HBase

Configuration hConf = HBaseConfiguration.create(conf); hConf.set(Constants.HBASE_CONFIGURATION_ZOOKEEPER_QUORUM, hbaseZookeeperQuorum); hConf.setInt(Constants.HBASE_CONFIGURATION_ZOOKEEPER_CLIENTPORT, hbaseZookeeperClientPort);  HTable hTable = new HTable(hConf, tableName); 

HTH

EDIT: Example Values:

public static final String HBASE_CONFIGURATION_ZOOKEEPER_QUORUM                     = "hbase.zookeeper.quorum"; public static final String HBASE_CONFIGURATION_ZOOKEEPER_CLIENTPORT                 = "hbase.zookeeper.property.clientPort"; ... hbaseZookeeperQuorum="PDHadoop1.corp.CompanyName.com,PDHadoop2.corp.CompanyName.com"; hbaseZookeeperClientPort=10000; tableName="HBaseTableName"; 
like image 105
QuinnG Avatar answered Sep 24 '22 03:09

QuinnG