Shankramma Patil
Shankramma Patil

Reputation: 31

Unable to Connect to Hbase through Java

I am trying to connect to Hbase from Java. Hbase -Version 1.0.0 But I am unable to connect it. Kindly tell me what I am missing as I am new to Hbase. Here is my code

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


    Configuration conf = HBaseConfiguration.create();
    conf.set("hbase.master","LocalHost:60000");
    conf.set("hbase.zookeeper.property.clientPort", "2181");
    conf.set("hbase.zookeeper.quorum", "LocalHost");
    conf.set("zookeeper.znode.parent", "/hbase-unsecure");
    System.out.println("Config set");
    Connection conn = ConnectionFactory.createConnection(conf);
    System.out.println("Connection");
    Admin admin = conn.getAdmin();
    if (!admin.tableExists(tableName)) {
        System.out.println("In admin");
        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));
    table.put(p);

    Result r = table.get(new Get(Bytes.toBytes("AAPL10232015")));
    System.out.println(r);
}

Below is the error I am facing :

Exception in thread "main" org.apache.hadoop.hbase.client.RetriesExhaustedException: Can't get the locations
at org.apache.hadoop.hbase.client.RpcRetryingCallerWithReadReplicas.getRegionLocations(RpcRetryingCallerWithReadReplicas.java:305)
at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:131)
at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:56)
at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:200)
at org.apache.hadoop.hbase.client.ClientScanner.call(ClientScanner.java:287)
at org.apache.hadoop.hbase.client.ClientScanner.nextScanner(ClientScanner.java:267)
at org.apache.hadoop.hbase.client.ClientScanner.initializeScannerInConstruction(ClientScanner.java:139)
at org.apache.hadoop.hbase.client.ClientScanner.<init>(ClientScanner.java:134)
at org.apache.hadoop.hbase.client.HTable.getScanner(HTable.java:823)
at org.apache.hadoop.hbase.MetaTableAccessor.fullScan(MetaTableAccessor.java:601)
at org.apache.hadoop.hbase.MetaTableAccessor.tableExists(MetaTableAccessor.java:365)
at org.apache.hadoop.hbase.client.HBaseAdmin.tableExists(HBaseAdmin.java:281)
at com.tcs.healthcare.HbaseRetrieveData.main(HbaseRetrieveData.java:32)

Kindly guide me through this

Upvotes: 0

Views: 1511

Answers (1)

Ram Ghadiyaram
Ram Ghadiyaram

Reputation: 29145

change L in localhost to l and 'H' to 'h'

Configuration conf = HBaseConfiguration.create();
    conf.set("hbase.master","localhost:60000");
    conf.set("hbase.zookeeper.property.clientPort", "2181");
    conf.set("hbase.zookeeper.quorum", "localhost");
    conf.set("zookeeper.znode.parent", "/hbase-unsecure");

If you are using remote machine, then conf.set("hbase.master","remotehost:60000"); even its not working then you check all the jars (which are remote) in the classpath

if you are using maven you can point to the jars which are there in cluster.

you can go to cluster and check below command to know the version of jars which are there in remote machine.

`hbase classpath`

Same version jars should be there in your client machine. For ex hbasex.jar in the remote machine and you are using hbasey.jar then it wont connect.

Moreover, please check from client machine you can able to ping server/cluster or not. Generally there will be firewall restrictions.

Upvotes: 0

Related Questions