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

问题描述 投票:1回答:1

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

InsertData.java:31:错误:HTable类中的构造函数HTable无法应用于给定类型;HTable hTable =新的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();
   }
}


我的帮助?

谢谢

java hadoop hbase
1个回答
0
投票

我不确定您使用的是哪个版本的HBase,但是HTable已经过时了一段时间(请参阅HTable API docs),现在纯粹是一种内部方法。而是使用HTable(确保版本与您的HBase部署保持一致):

您应该依赖Table(不需要任何其他HBase依赖项,并使用以下方法:

Table
© www.soinside.com 2019 - 2024. All rights reserved.