Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

how is this code working ?

Highlighted

how is this code working ?

Master Collaborator

I am not specifying anything about the hbase server or the zookeeper but this code works fine and hbase table gets created , how does the code know where to connect to hbase server?

[root@hadoop1 ~]# more TestHbaseTable.java
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;

public class TestHbaseTable
{
public static void main(String[] args) throws IOException
{
HBaseConfiguration hconfig = new HBaseConfiguration(new Configuration());
HTableDescriptor htable = new HTableDescriptor("User");
htable.addFamily( new HColumnDescriptor("Id"));
htable.addFamily( new HColumnDescriptor("Name"));
System.out.println( "Connecting..." );
HBaseAdmin hbase_admin = new HBaseAdmin( hconfig );
System.out.println( "Creating Table..." );
hbase_admin.createTable( htable );
System.out.println("Done!");
}
}

2 REPLIES 2

Re: how is this code working ?

You are running the application in a way that includes the directory containing hbase-site.xml on the classpath.

Re: how is this code working ?

Master Collaborator

so if the hbase-site.xml directory is in the classpath then no connection information needs to be given in the java code?