且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

HTable(config,tablename)类型已被弃用。有什么用呢?

更新时间:2023-12-05 10:31:52

手动构建 HTable 已被弃用。请使用 连接 来实例化



通过连接,可以使用 Connection.getTable(TableName)



  Connection connection = ConnectionFactory.createConnection(config); 

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

尝试
{
//根据需要使用表,对于单个操作和单个线程
}
finally
{
table.close();
connection.close();
}


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.

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