Search code examples
javahadoophbasedeprecated

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


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.


Solution

  • 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();
    }