Home > HBase, Java > Creating a HBase table through Java program

Creating a HBase table through Java program

To create a HBase table through Java program. We need to use HBaseConfiguration class

this is the main class which holds the configuration details about HBase.

then we have to add our hbase-site.xml to the HBaseConfiguration.
After preparing the configuration correctly pass this to HBaseAdmin. To specify the HBase table name HTableDescriptor will be used and

HColumnDescriptor is used for Column names.

After all set up is done call the createTable method of HBaseAdmin

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 HbaseTableCreator {

  public static void main(String[] args) throws Exception {

   HBaseConfiguration conf = new HBaseConfiguration();

   HBaseAdmin hbase = new HBaseAdmin(conf);
   HTableDescriptor desc = new HTableDescriptor("sample");
   HColumnDescriptor meta = new HColumnDescriptor("samplecolumn1".getBytes());
   HColumnDescriptor prefix = new HColumnDescriptor("samplecolumn2".getBytes());



After successful running of the above program, check with hbase shell whether the table is created or not.

Categories: HBase, Java
  1. ganesh
    July 1, 2014 at 9:54 am

    Getting following exception :-Exception in thread “main” java.lang.IllegalArgumentException: Illegal character . Family names cannot contain control characters or colons: number:

  2. August 30, 2014 at 1:55 pm

    Hi, after reading this remarkable piece of writing i am as
    well cheerful to share my knowledge here with mates.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: