HBase Create Table with Java API & Shell Example
โก Smart Summary
HBase stores data in tables, and you can create and handle those tables two ways: through the Java API with HTableDescriptor and HBaseAdmin, or directly in the HBase shell using the create command.

How to Create Table in HBase with Java API
In HBase, tables can be created in two ways: through the Java API and through the HBase shell. This section covers the Java API, which lets an application create tables and load data programmatically as part of a larger job.
Through Java API, we can create tables in HBase and also load data into tables using Java coding. The two things we set up here are:
- Establishing a connection with HBase through Java API.
- Using Eclipse for Java coding, debugging, and testing.
Following are the steps to create tables in HBase through Java API.
Step 1) Create a Java Project in Eclipse
In this step, we are going to create a Java project in Eclipse for the HBase connection, named “HbaseConnection”.
The New Java Project dialog below shows the “HbaseConnection” project being set up:
If we observe the screenshot above:
- Give the project name in this box. In our case, the project name is “HbaseConnection”.
- Check this box for the default location to be saved. Here /home/hduser/work/HbaseConnection is the path.
- Check the box for the Java environment here. In this case JavaSE-1.7 is the Java edition.
- Choose the option for where you want to save the file. In our case, we selected the second option, “Create a separate folder for sources and class files”.
- Click on the Finish button, which creates the “HbaseConnection” project in Eclipse and opens the Eclipse home page.
Step 2) Configure the Build Path in Eclipse
On the Eclipse home page, follow these steps to open the build path configuration:
Right click on project -> Select Build Path -> Configure build path
The screenshot below shows the right-click menu used to open the build path configuration:
From the above screenshot:
- Right-click on a project.
- Select Build Path.
- Select Configure Build Path.
After clicking Configure Build Path, it opens another window, shown in the screenshot below. The Libraries tab is where the HBase and Hadoop JAR files are added to the project:
In this step, we add the relevant HBase JARs into the Java project as shown in the screenshot.
- Important JARs to be added: hbase-0.94.8.jar and hadoop-core-1.1.2.jar.
- Come to the Libraries tab.
- Press the option Add External JARs.
- Select the required important JARs.
- Press the Finish button to add these files to the “src” of the Java project under Libraries.
After the JARs are added, they appear under the project “src” location as shown below:
All the JAR files that fall under the project are now ready for usage with the Hadoop ecosystem.
Step 3) Establish the HBase Connection
In this step, using HBaseConnection.java, the HBase connection is established through Java coding.
On the Eclipse top menu, execute a Java program as shown below: Run -> Run As -> Java Application. The menu below shows the program being launched:
- Select Run.
- Select Run As Java Application.
- This code establishes a connection with HBase through Java API.
- After running this code, the “guru99” table is created in HBase with two column families named “education” and “projects”. At present, only the empty schema is created in HBase.
The code excerpt below highlights the HTableDescriptor and addFamily calls that build the table schema:
From the screenshot above, we are performing the following functions:
- Using HTableDescriptor, we can create the “guru99” table in HBase.
- Using the addFamily method, we add “education” and “projects” as column families to the “guru99” table.
The code below is going to establish a connection with HBase and create the “guru99” table with two column families. Place this code under the HBaseConnection.java document:
// Place this code inside Hbase connection 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 HBaseConnection { public static void main(String[] args) throws IOException { HBaseConfigurationhc = new HBaseConfiguration(new Configuration()); HTableDescriptorht = new HTableDescriptor("guru99"); ht.addFamily( new HColumnDescriptor("education")); ht.addFamily( new HColumnDescriptor("projects")); System.out.println( "connecting" ); HBaseAdminhba = new HBaseAdmin( hc ); System.out.println( "Creating Table" ); hba.createTable( ht ); System.out.println("Done......"); } }
This is the required code you have to place in HBaseConnection.java before you run the Java program.
After running this program, it establishes a connection with HBase and, in turn, creates a table with column names.
- The table name is “guru99”.
- Column families are “education” and “projects”.
Step 4) Check the Created Table in HBase
We can check whether the “guru99” table is created with two column families in HBase by using HBase shell mode with the “list” command. The “list” command gives information about all the tables created in HBase.
Running the list command in the HBase shell confirms the new table, as shown below:
- Code checking in the HBase shell by executing the “list” command.
- If we run the “list” command, it displays the table created in HBase. In our case, we can see the “guru99” table is created.
HBase Create Table with Shell
Besides the Java API, you can create a table directly from the HBase shell, which is the fastest way to set up a table for quick tests. The syntax to create a table in HBase using the shell is:
Syntax: create <tablename>, <columnfamilyname>
Example:-
hbase(main):001:0> create 'education' ,'guru99' 0 rows(s) in 0.312 seconds =>Hbase::Table โ education
The above example explains how to create a table in HBase with the specified name given according to the specifications for each column family. In addition to this, we can also pass some table-scope attributes into it.
create 'guru99', {NAME=>'Edu', VERSIONS=>213423443}
Here the {NAME=>’Edu’, VERSIONS=>…} block sets a column family named “Edu” and the number of cell versions it keeps. The large number is only illustrative; in practice, VERSIONS is a small value such as 3 or 5.
List, Describe, and Verify HBase Tables
Creating a table is only the first part of handling tables in HBase. Once the “guru99” table exists, a few general commands let you inspect it and confirm its state before you read, write, or modify data. You can run all of them from the HBase shell.
The list command returns every user table in HBase:
hbase> list
The describe command shows a table’s structure, including its column families and whether it is currently enabled:
hbase> describe 'guru99'
The exists command checks whether a table is present, and is_enabled reports whether the table can accept writes:
hbase> exists 'guru99' hbase> is_enabled 'guru99'
These read-only checks are safe to run at any time. They are the quickest way to confirm that a table was created correctly and to review its column families before loading data.
Alter an HBase Table
An HBase table schema is not fixed after creation. The alter command changes a table’s column families and table-scope attributes without recreating it. Depending on your HBase version, you may need to disable the table first, then run alter and enable it again.
To add a new column family to the “guru99” table:
hbase> alter 'guru99', {NAME => 'contact'}
To set how many versions a column family keeps:
hbase> alter 'guru99', NAME => 'education', VERSIONS => 5
To delete a column family from the table:
hbase> alter 'guru99', {NAME => 'contact', METHOD => 'delete'}
You can also change table-scope attributes. For example, mark the table read-only, or set the maximum region file size to 128 MB:
hbase> alter 'guru99', READONLY hbase> alter 'guru99', MAX_FILESIZE => '134217728'
Because alter rewrites the schema, plan changes carefully on a production table, and confirm the result afterward with describe.
Disable, Enable, and Drop HBase Tables
To remove a table or apply certain changes, HBase requires you to disable it first. Disabling takes the table offline so no client can read or write to it, which makes structural changes safe.
Disable a table, and check its state with is_disabled:
hbase> disable 'guru99' hbase> is_disabled 'guru99'
Enable the table again to resume reads and writes:
hbase> enable 'guru99'
A table must be disabled before it can be dropped. Dropping deletes the table and all of its data permanently, so use it with care:
hbase> disable 'guru99' hbase> drop 'guru99'
To remove several tables at once, drop_all deletes every table whose name matches a regular expression. Together, create, alter, disable, enable, and drop cover the full life cycle of handling data in HBase tables.






