error: constructor HTable in class HTable cannot be applied to given types

error: constructor HTable in class HTable cannot be applied to given types

我正在使用 hadoop hbase。我只是写了一个简单的程序来插入数据库数据库。当我 运行 程序时出现以下错误:

InsertData.java:31: 错误:class HTable 中的构造函数 HTable 无法应用于给定类型; HTable hTable = new HTable("emp", conn);

我的代码:


import java.io.IOException;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;

public class InsertData {

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

      // Instantiating Configuration class
      Configuration config = HBaseConfiguration.create();

      // Instantiating HTable class
      HTable hTable = new HTable(config, "emp");

      // Instantiating Put class
      // accepts a row name.
      Put p = new Put(Bytes.toBytes("row1")); 

      // adding values using add() method
      // accepts column family name, qualifier/row name ,value
      p.add(Bytes.toBytes("personal"),
      Bytes.toBytes("name"),Bytes.toBytes("raju"));

      p.add(Bytes.toBytes("personal"),
      Bytes.toBytes("city"),Bytes.toBytes("hyderabad"));

      p.add(Bytes.toBytes("professional"),Bytes.toBytes("designation"),
      Bytes.toBytes("manager"));

      p.add(Bytes.toBytes("professional"),Bytes.toBytes("salary"),
      Bytes.toBytes("50000"));

      // Saving the put Instance to the HTable.
      hTable.put(p);
      System.out.println("data inserted");

      // closing HTable
      hTable.close();
   }
}


我的帮助?

谢谢

我不确定您使用的是哪个版本的 HBase,但 HTable 已被弃用一段时间(请参阅 HTable API docs) and is now purely an internal method. Instead, use Table(确保版本与您的 HBase 部署保持一致):

你应该依赖org.apache.hbase:hbase-client:<VERSION>(不需要任何其他HBase依赖),并使用以下方法:

try {
  Configuration conf = HBaseConfiguration.create();
  Connection connection = ConnectionFactory.createConnection(conf);
  Table table = connection.getTable(TableName.valueOf("emp"));

  Put p = new Put(Bytes.toBytes("row1"));
  p.add(Bytes.toBytes("personal"), Bytes.toBytes("name"),Bytes.toBytes("raju"));

  table.put(p);
} finally {
  table.close();
  connection.close();
}