简体   繁体   English

无法使用Java连接到HBase?

[英]Unable to connect to HBase using Java ?

Before asking this questions i searched a lot to solve the below issue but couldn't solve, if anyone can help on this. 在问这个问题之前,我进行了很多搜索以解决以下问题,但是如果有人可以提供帮助,则无法解决。

I have installed hadoop1 2.5.0 and HBase 0.98.6 (in pseudo dist mode). 我已经安装了hadoop1 2.5.0和HBase 0.98.6(在伪dist模式下)。 I am trying to run a simple java program to retrieve data from hbase. 我正在尝试运行一个简单的Java程序以从hbase检索数据。 My all nodes are running. 我的所有节点都在运行。 My code is- 我的代码是-

Configuration conf = HBaseConfiguration.create();
conf.set("hbase.master","hadoopHost:60000");
conf.set("hbase.zookeeper.quorum", hBaseZookeeperHostName);
conf.set("hbase.zookeeper.property.clientPort", "2181");
System.out.println("hello");
HTableInterface table = HConnectionManager.createConnection(conf).getTable("user".getBytes());
System.out.println(table.getTableDescriptor().getColumnFamilies().toString());

It is printing hello and after that its getting stuck for some time and ends simply without any error or warning. 它正在打印问候,然后卡住一段时间并结束而没有任何错误或警告。

I am very new to this Big Data world, if someone can put his/her time to resolve this. 如果有人可以花时间解决这个问题,那么我对这个大数据世界还是陌生的。

There are two ways by which we can create configuration for HBase connection. 我们可以通过两种方式为HBase连接创建配置。

  1. We can use the below lines in your Class to create a connection and then set hbase-site.xml in your classpath. 我们可以在您的类中使用以下行来创建连接,然后在类路径中设置hbase-site.xml。

    Configuration conf = HBaseConfiguration.create; 配置conf = HBaseConfiguration.create; HTableInterface table = HConnectionManager.createConnection(conf).getTable("user".getBytes()); HTableInterface表= HConnectionManager.createConnection(conf).getTable(“ user” .getBytes());

By this way, the values defined in the hbase-site.xml will be used to create the connection. 这样,hbase-site.xml中定义的值将用于创建连接。

  1. If you want to override the values in hbase-site.xml you can remove hbase-site.xml from your classpath and set the parameter as required like you have mentioned in the above code. 如果要覆盖hbase-site.xml中的值,则可以从类路径中删除hbase-site.xml并根据需要设置参数,就像上面的代码中提到的那样。

Since you are trying to use the default values, I would suggest you to go with the option one. 由于您尝试使用默认值,因此建议您使用选项一。

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

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