简体   繁体   中英

Connecting to a table in HBase

I have created a table in HBase named notifications . I want to connect to this table to perform insert and delete operations.

The code I have used for creating a connection is:

Configuration conf = HBaseConfiguration.create();
Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(TableName.valueOf("notifications"));

But this does not seem to work.

Are you supplying hbase-site.xml together with the above code, and are you confident that your application is finding it properly?

Your application needs to know the zookeeper quorum address and port number to connect to. Normally you specify those in hbase-site.xml, which your application needs to be able to see. But if you want to be sure that you are connecting to the right place, you can set the most basic values programmatically directly in your code, like this:

Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "zk1,zk2,zk3");
conf.set("hbase.zookeeper.property.clientPort", "2181");
Connection connection = ConnectionFactory.createConnection(conf);
Table table = connection.getTable(TableName.valueOf("notifications"));

So the above assumes that you have 3 zk nodes zk1, zk2, and zk3, and they are using port 2181 (default value for hbase, but you can double-check in your hbase-site.xml on the server side)

What is the error that you are getting? Check if you have the hbase-site.xml & core-site.xml config files on the classpath. If not, add it to the config before creating the connection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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