Error: the constructor htable (configuration string) is deprecated Error: the constructor htable (configuration string) is deprecated hadoop hadoop

Error: the constructor htable (configuration string) is deprecated


It's just a warning. But you should not use deprecated methods in your code.

In place of :

HBaseAdmin admin = new HBaseAdmin(conf);

You should use:

Connection conn =ConnectionFactory.createConnection(conf);Admin admin  = conn.getAdmin();


Sample code for your reference. Assuming that you have Hbase running in standalone mode.

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.TableName;import org.apache.hadoop.hbase.client.Admin;import org.apache.hadoop.hbase.client.Connection;import org.apache.hadoop.hbase.client.ConnectionFactory;public class HBaseSample {    public static void main(String[] args) {        Configuration conf = HBaseConfiguration.create();        try {                       Connection conn = ConnectionFactory.createConnection(conf);            Admin hAdmin = conn.getAdmin();            HTableDescriptor hTableDesc = new HTableDescriptor(                    TableName.valueOf("Customer"));            hTableDesc.addFamily(new HColumnDescriptor("name"));            hTableDesc.addFamily(new HColumnDescriptor("contactinfo"));            hTableDesc.addFamily(new HColumnDescriptor("address"));            hAdmin.createTable(hTableDesc);            System.out.println("Table created Successfully...");        } catch (Exception e) {            e.printStackTrace();        }    }}


If you need to retrieve a table for usage, you can use Connection.getTable(TableName)

But If you need to create a table instead, use TableDescriptorBuilder and Admin.createTable(TableDescriptor)

For instance:

val tableDescriptor: TableDescriptor = TableDescriptorBuilder                          .newBuilder(TableName.valueOf("mytable"))                          .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder("myId".getBytes).build())                          .setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder("data".getBytes).build())                          .build()admin.createTable(tableDescriptor)