简体   繁体   English

无法使用Java连接到Hbase

[英]Unable to Connect to Hbase using Java

Hi i have installed ubuntu on my machine and installed hbase0.98-hadoop2. 嗨,我已经在我的机器上安装了ubuntu并安装了hbase0.98-hadoop2。 Then i edited hbase-env.sh file and hbase-site.xml. 然后,我编辑了hbase-env.sh文件和hbase-site.xml。 Now my hbase shell is working fine. 现在我的hbase shell运行正常。 But when i try to connect to hbase from Java code using hbase java api's. 但是当我尝试使用hbase java api从Java代码连接到hbase时。 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. 我的代码在HbaseAdmin上造成了问题。 Any help please? 有什么帮助吗? Remember i installed standalone hbase and did not installed hadoop separately. 记住我安装了独立的hbase,没有单独安装hadoop。 It was the same package hbase0.98.6-hadoop2. 它与hbase0.98.6-hadoop2相同。

If you are using maven, please see if you are using the exact versioned dependencies as your hbase setup is. 如果您正在使用Maven,请查看您是否正在使用与hbase设置完全相同的版本化依赖项。 Foexample, if your hbase is suppose hbase-0.xx you must add the dependency hbase-0.xx in your project. 举例来说,如果您的hbase假设为hbase-0.xx,则必须在项目中添加依赖项hbase-0.xx。 Similarly check all other dependencies like hadoop, zookeeper as well. 同样检查所有其他依赖项,例如hadoop,zookeeper。 If not maven then download the proper jars and add them to your classpath. 如果不是maven,则下载正确的jar并将其添加到您的类路径中。 If you are unaware, go to the lib folder of your application and see the jars. 如果您不知道,请转到应用程序的lib文件夹并查看jar。

Hope this helps. 希望这可以帮助。 Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM