java - 错误:类HTable中的构造函数HTable无法应用于给定类型

标签 java hadoop hbase

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

InsertData.java:31:错误: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),现在纯粹是一种内部方法。而是使用 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();
}

关于java - 错误:类HTable中的构造函数HTable无法应用于给定类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60126227/

相关文章:

hadoop - 如何在hadoop中设计具有两个输入的Mapper

java - 从 Java 程序运行 Hadoop 作业

database - HBase区域中的数据可以根据family:column的值手动进行排列

hadoop - HBase regionserver 被中止,之后再也无法启动

hadoop - 2n + 1 法定人数是什么意思?

java - 我如何打印线程状态?

java - MapReduce 计数问题

java - 使用 cookie 在 Spring-MVC 中使用 ICU 进行本地化

hadoop - 启用 hadoop 和 kerberos 的 datastax enterprise 出错

Java for循环从0到0