hbase Connecting to HBase


Example

If you want to connect to an HBase server, first you need to make sure that the IP of the server is in your /etc/hosts file for example add the line

255.255.255.255    hbase

Then you can use the Java API to connect to zookeeper, you only have to specify the client port and the zookeeper address

Configuration config =  HBaseConfiguration.create();
config.set("hbase.zookeeper.quorum", "hbase");
config.set("hbase.zookeeper.property.clientPort","2181");

After you configured the connection, you can test it, using

HBaseAdmin.checkHBaseAvailable(config);

If you have a problem with your HBase configuration, an exception will be thrown.

Finally to connect to the server, just use

Connection connection = ConnectionFactory.createConnection(config);