In this tutorial I will show you how to connect to an Unsecure HBASE using Java. It’s rather straight forward. This tutorial assumes no security. There are so many different options you can set we will just take the bare minimum so you can connect.
POM:
<dependency> <groupId>org.apache.hbase</groupId> <artifactId>hbase-client</artifactId> <version>1.4.1</version> </dependency> <dependency> <groupId>org.apache.hbase</groupId> <artifactId>hbase</artifactId> <version>1.4.1</version> <type>pom</type> </dependency>
Imports:
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.ConnectionFactory;
Config:
We will use the basic configuration here. You should secure the cluster and use appropriate settings for that.
final Configuration config = HBaseConfiguration.create(); config.set("hbase.zookeeper.quorum", "myurl.com"); //Can be comma seperated if you have more than 1 config.set("hbase.zookeeper.property.clientPort", "2181"); config.set("zookeeper.znode.parent", "/hbase-unsecure");
Connect:
Now we create the connection.
Connection conn = ConnectionFactory.createConnection(config); //Later when we are done we will want to close the connection. conn.close();
Hbase Admin:
Retrieve an Admin implementation to administer an HBase cluster. If you need it.
Admin admin = conn.getAdmin(); //Later when we are done we will want to close the connection. admin.close();
2 thoughts on “HBASE: Connecting Unsecure”
Comments are closed.