Support Questions
Find answers, ask questions, and share your expertise
Check out our newest addition to the community, the Cloudera Innovation Accelerator group hub.

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
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 );


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

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?