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(); conf.addResource("conf/hbase-site.xml"); conf.set("hbase.master","localhost:60000"); HBaseAdmin hbase = new HBaseAdmin(conf); HTableDescriptor desc = new HTableDescriptor("sample"); HColumnDescriptor meta = new HColumnDescriptor("samplecolumn1".getBytes()); HColumnDescriptor prefix = new HColumnDescriptor("samplecolumn2".getBytes()); desc.addFamily(meta); desc.addFamily(prefix); hbase.createTable(desc); } }
After successful running of the above program, check with hbase shell whether the table is created or not.
Getting following exception :-Exception in thread “main” java.lang.IllegalArgumentException: Illegal character . Family names cannot contain control characters or colons: number:
Hi, after reading this remarkable piece of writing i am as
well cheerful to share my knowledge here with mates.