Frankie Frankie - 2 months ago 62x
Java Question

Java API to HBase exception:cannot get location

I am trying to use JAVA API to connect to HBase.
My codes are shown below:

public class Test {
public static void main(String[] args) throws IOException{
TableName tableName = TableName.valueOf("TABLE2");

Configuration conf = HBaseConfiguration.create();
conf.set("zookeeper.znode.parent", "/hbase-secure");
conf.set("", "2181");
conf.set("hbase.zookeeper.quorum", "xxxxxxxxxxxxxx");
conf.set("hbase.master", "xxxxxxxxxxxxx");

Connection conn = ConnectionFactory.createConnection(conf);
Admin admin = conn.getAdmin();

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

When I run this program in my cluster, I got exception:
I ran this and got error below:

Exception in thread "main" org.apache.hadoop.hbase.client.RetriesExhaustedException: Can't get the locations
at org.apache.hadoop.hbase.client.RpcRetryingCallerWithReadReplicas.getRegionLocations(
at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(
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 java2hbase.Test.main(

I ran this in a HDP cluster, exception happens after hbaseAdmin instantiation. It seems that JAVA client is not able to connect to Hbase using zookeeper, but I can use command "hbase zkcli" to open shell successfully.

Anyone knows what is problem? Is there any way to check zookeeper is good or not? Any help is appreciated.


This seems to be an issue with the cluster. Can you make sure that HBase is happy and healthy and all Region servers are up and running?

Please open the shell and list the tables first to ensure basic check..

If you are running from the cluster below is sure shot approach to avoid any surprises.

Configuration conf = HBaseConfiguration.create();

also check that below way you are running java client

# export HADOOP_CLASSPATH=`./hbase classpath`