Community Articles
Find and share helpful community-sourced technical articles
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.
Labels (1)

I had a hard time finding sample code online that uses the latest HBase 1.1+ Java APIs to connect to HDP 2.3 Sandbox. Here is my version for those that already know the Java basics.

public static void main(String[] args) throws IOException {
    TableName tableName = TableName.valueOf("stock-prices");

    Configuration conf = HBaseConfiguration.create();
    conf.set("", "2181");
    conf.set("hbase.zookeeper.quorum", "");
    conf.set("zookeeper.znode.parent", "/hbase-unsecure");
    Connection conn = ConnectionFactory.createConnection(conf);
    Admin admin = conn.getAdmin();
    if (!admin.tableExists(tableName)) {
        admin.createTable(new HTableDescriptor(tableName).addFamily(new HColumnDescriptor("cf")));

    Table table = conn.getTable(tableName);
    Put p = new Put(Bytes.toBytes("AAPL10232015"));
    p.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("close"), Bytes.toBytes(119));

    Result r = table.get(new Get(Bytes.toBytes("AAPL10232015")));

Add these dependencies through Maven of Gradle:


Then set hbase.regionserver.ipc.address= through Ambari if your Sandbox runs in a VM with multiple NICs.

New Contributor

Hi, Very useful article. I tried this exact code snippet. But, failing. Any help will be appreciated :

I am no HDP 2.4.

Exception in thread "main" java.lang.RuntimeException: java.lang.NullPointerException at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries( at at org.apache.hadoop.hbase.client.ClientScanner.nextScanner( at org.apache.hadoop.hbase.client.ClientScanner.initializeScannerInConstruction( at org.apache.hadoop.hbase.client.ClientScanner.<init>( at org.apache.hadoop.hbase.client.HTable.getScanner( at org.apache.hadoop.hbase.MetaTableAccessor.fullScan( at org.apache.hadoop.hbase.MetaTableAccessor.tableExists( at org.apache.hadoop.hbase.client.HBaseAdmin.tableExists( at at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke( at sun.reflect.DelegatingMethodAccessorImpl.invoke( at java.lang.reflect.Method.invoke( at com.intellij.rt.execution.application.AppMain.main( Caused by: java.lang.NullPointerException at org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher.getMetaReplicaNodes( at org.apache.hadoop.hbase.zookeeper.MetaTableLocator.blockUntilAvailable( at org.apache.hadoop.hbase.client.ZooKeeperRegistry.getMetaRegionLocation( at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateMeta( at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.locateRegion( at org.apache.hadoop.hbase.client.RpcRetryingCallerWithReadReplicas.getRegionLocations( at at at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries( ... 14 more

Not applicable

This is very helpful article but I'm getting error when I tared to create the table into HBase as per your all above mentioned steps and dependencies.

Pls have a look it.

Is there any more properties to set in HBase-site.xml or something other?

File are attached here.



Not applicable

sorry to mention, I have have updated my ipAddress in conf.set("hbase.zookeeper.quorum", "ipAddress");

New Contributor

@Vladimir Zlatkin form where we get these dependencies in jar files?

Don't have an account?
Coming from Hortonworks? Activate your account here
Version history
Revision #:
1 of 1
Last update:
‎10-23-2015 10:59 PM
Updated by:
Top Kudoed Authors