TECH SOLUTIONS

Click here to edit subtitle

Forums

Post Reply
Forum Home > Bigdata Learnings( Hadoop, HBase,Hive and other bigdata technologies) > HBase: create table using HBaseAdmin API

Sourav Gulati
Site Owner
Posts: 83

In HBase we can create table from HBase shell as follows:

hbase(main):005:0> create 'table_name','column_family_name'


However, you can also create table using HBaseAdmin API as follows:


public class AdminCreate {

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

        

    

    Configuration conf = HBaseConfiguration.create();

    HBaseAdmin admin = null;

    try{

        admin=new HBaseAdmin(conf);

       }

    catch(Exception e)

       {

        e.printStackTrace();

        

       }

    

    HTableDescriptor tabdesc = new HTableDescriptor("newtable");

    HColumnDescriptor colfam=new HColumnDescriptor("colfam");

    tabdesc.addFamily(colfam);

    

    admin.createTable(tabdesc);

    

    if(admin.isTableAvailable("newtable")==true)

    {

        System.out.println("Table created");

    }

    else

    {

        System.out.println("Table was not created");

    }

    

    

    }

       

}





Click here for Other topics of BigData Technologies

 

February 12, 2013 at 4:55 AM Flag Quote & Reply

You must login to post.