Creating Hbase Table using Java

I am trying to create Hbase table using Java source code.
This is my source code

import java.io.IOException;
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;
import org.apache.hadoop.hbase.TableName;

import org.apache.hadoop.conf.Configuration;

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

      Configuration con = HBaseConfiguration.create();

      HBaseAdmin admin = new HBaseAdmin(con);

      HTableDescriptor tableDescriptor = new
      HTableDescriptor(TableName.valueOf("z_utk_emp"));

      tableDescriptor.addFamily(new HColumnDescriptor("personal"));
      tableDescriptor.addFamily(new HColumnDescriptor("professional"));

      admin.createTable(tableDescriptor);
      System.out.println(" Table created ");
   }
}

I compiled the program using these commands on the command line
javac -Xlint:overrides -cp "/usr/hdp/current/hadoop-client/*:/usr/hdp/current/hbase-client/lib/*" hbaseRelated.java

Then I made the program run by using the command:
java -cp ".:/usr/hdp/current/hadoop-client/*:/usr/hdp/current/hbase-client/lib/*" hbaseRelated

QUESTION:
I am not able to create the table using this method in HBase
The errors are
Exception in thread “main” org.apache.hadoop.hbase.client.RetriesExhaustedException: Failed after attempts=35, exceptions:

Caused by: org.apache.hadoop.hbase.MasterNotRunningException: java.io.IOException: Can’t get master address from ZooKeeper; znode data == null

Caused by: java.io.IOException: Can’t get master address from ZooKeeper; znode data == null

ANY SOLUTIONS?

While experimenting I put the following values at appropriate place
Configuration conf = HBaseConfiguration.create();
conf.addResource("/home/uutkarshsingh7351/core-site.xml");
conf.addResource("/home/uutkarshsingh7351/hbase-site.xml");
conf.addResource("/home/uutkarshsingh7351/hdfs-site.xml");

I place the required xml files at the path that has been mentioned but got some different kind
of errors.

1 Like

Are you still facing this issue?

Yes I am stuck
. Is it possible for you to help me on this. I have posted this on many places on this forum but of no avail.

@utkarsh_rathor,

Can you please refer below:

Hi,

I am facing the same issue. I created a JAR file to read and write to HBase table.

But receiving this exception:
Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/hadoop/hbase/MasterNotRunningException
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.apache.hadoop.util.RunJar.run(RunJar.java:226)
at org.apache.hadoop.util.RunJar.main(RunJar.java:148)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.hbase.MasterNotRunningException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

The command i am using is:
HADOOP_CLASSPATH=‘hbase classpath’ hadoop jar HBase_Customize.jar H
BaseCustomJAR

I tried running this command to start the HBase master service but didnt work:
sudo service hbase-master start

Can you please advise the fix for this?

I think it should be:
HADOOP_CLASSPATH=`hbase classpath`

Did you notice the difference? It is backquote not single quote.