Unable to Connect to Hbase using Java

房东的猫 提交于 2019-12-11 09:32:19

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/26019577/unable-to-connect-to-hbase-using-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!