The type HTable(config,tablename) is deprecated. What use instead?

dino picture dino · Oct 25, 2015 · Viewed 8.5k times · Source

What can I use instead of HTable(config,tablename)?

This method is deprecated. In every example I could find they use this or another Constuctor, which is also deprecated.

Answer

Vinkal picture Vinkal · Oct 26, 2015

Constructing HTable objects manually has been deprecated. Please use Connection to instantiate a Table instead.

From a Connection, Table implementations are retrieved with Connection.getTable(TableName)

Example:

Connection connection = ConnectionFactory.createConnection(config);

Table table = connection.getTable(TableName.valueOf("table1"));

try 
{
   // Use the table as needed, for a single operation and a single thread
} 
finally
{
   table.close();
   connection.close();
}