Mr37037
Mr37037

Reputation: 748

Unable to Connect to Hbase using Java

Hi i have installed ubuntu on my machine and installed hbase0.98-hadoop2. Then i edited hbase-env.sh file and hbase-site.xml. Now my hbase shell is working fine. But when i try to connect to hbase from Java code using hbase java api's. I get errors. My Code is:

Configuration hc = HBaseConfiguration.create();


          HTableDescriptor ht = new HTableDescriptor("User"); 

          ht.addFamily( new HColumnDescriptor("Id"));

          ht.addFamily( new HColumnDescriptor("Name"));

          System.out.println( "connecting" );

          HBaseAdmin hba = new HBaseAdmin( hc );
          System.out.println( "Master running ? "+ hba.isMasterRunning());
          System.out.println( "Creating Table" );

          hba.createTable( ht );

          System.out.println("Done......");

My output is:

connecting
Exception in thread "main" java.lang.NumberFormatException: For input string: "42529`;��7ec�PBUF

jamil-37037�������)
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    at java.lang.Integer.parseInt(Integer.java:492)
    at java.lang.Integer.parseInt(Integer.java:527)
    at org.apache.hadoop.hbase.HServerAddress.<init>(HServerAddress.java:63)
    at org.apache.hadoop.hbase.MasterAddressTracker.getMasterAddress(MasterAddressTracker.java:63)
    at org.apache.hadoop.hbase.client.HConnectionManager$HConnectionImplementation.getMaster(HConnectionManager.java:353)
    at org.apache.hadoop.hbase.client.HBaseAdmin.<init>(HBaseAdmin.java:89)
    at HBaseConnector.main(HBaseConnector.java:157)

My Code is creating problem at HbaseAdmin. Any help please? Remember i installed standalone hbase and did not installed hadoop separately. It was the same package hbase0.98.6-hadoop2.

Upvotes: 1

Views: 1202

Answers (1)

SSC
SSC

Reputation: 3008

If you are using maven, please see if you are using the exact versioned dependencies as your hbase setup is. Foexample, if your hbase is suppose hbase-0.x.x you must add the dependency hbase-0.x.x in your project. Similarly check all other dependencies like hadoop, zookeeper as well. If not maven then download the proper jars and add them to your classpath. If you are unaware, go to the lib folder of your application and see the jars.

Hope this helps. Thanks

Upvotes: 2

Related Questions