Hive JDBC error: java.lang.NoSuchFieldError: HIVE_CLI_SERVICE_PROTOCOL_V7

梦想与她 提交于 2019-12-12 04:34:25

问题


I'm trying to create a connection via JDBC to Impala using the Hive2 connector. But I'm getting this error:

Exception in thread "main" java.lang.NoSuchFieldError: HIVE_CLI_SERVICE_PROTOCOL_V7
      at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:175)
      at org.apache.hive.jdbc.HiveDriver.connect(HiveDriver.java:105)
      at java.sql.DriverManager.getConnection(DriverManager.java:664)
      at java.sql.DriverManager.getConnection(DriverManager.java:208)
      at dsnoc.dsnoc_api.dolar.getDolarFromImpala(dolar.java:145)
      at dsnoc.dsnoc_api.dsnoc.main(dsnoc.java:75)

I don't know if it is a depencency compatibility issue:

  <dependency>
      <groupId>org.apache.hive</groupId>
      <artifactId>hive-exec</artifactId>
      <version>1.1.0</version>
  </dependency>
  <dependency>
      <groupId>org.apache.hive</groupId>
      <artifactId>hive-jdbc</artifactId>
      <version>1.1.0</version>
  </dependency>
  <dependency>
      <groupId>org.apache.hadoop</groupId>
      <artifactId>hadoop-common</artifactId>
      <version>2.6.0</version>
  </dependency>

I'm using CDH 5.8.0 with Hive 1.1.0 and Hadoop 2.6.0

Or maybe is Code issue:

public static double getDolarFromImpala(String date)  {
    double dolar = 0.0;
    try {
        Class.forName(JDBC_DRIVER_HIVE);
        String sql = "SELECT valor FROM dolar where fecha ='"+date+"'";

        Connection con = DriverManager.getConnection(JDBC_HIVE2_URL,USERNAME,PASSWORD);
        Statement stmt = con.createStatement();
        ResultSet rs = stmt.executeQuery(sql);

        while(rs.next()){
            dolar = rs.getDouble("valor");                                          
        }
        stmt.close();
        con.close();
    }
    catch(SQLException se){
          //Handle errors for JDBC
          se.printStackTrace();
    }
    catch(Exception e){
          //Handle errors for Class.forName
          e.printStackTrace();
    }
    return dolar;
}

But I think is not, because I tried it with an Impala-JDBC and worked.

Other thing is that I'm not using the Impala-JDBC because it don't reads or sends the USERNAME and PASSWORD, throwing me this error:

 [Simba][ImpalaJDBCDriver](500051) ERROR processing query/statement. Error Code: 0, SQL state: TStatus(statusCode:ERROR_STATUS, sqlState:HY000, errorMessage:AuthorizationException: User '' does not have privileges to execute 'SELECT'

Regards,


回答1:


Try this jars:

  • hive-jdbc-2.1.1-standalone.jar
  • hadoop-common-2.7.3.jar

depencency:

<dependency>
    <groupId>org.apache.hive</groupId>
    <artifactId>hive-jdbc</artifactId>
    <version>2.1.1</version>
</dependency>
<dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-common</artifactId>
    <version>2.7.3</version>
</dependency>

You can find this jars here: https://search.maven.org

This jars working for me in JMeter.



来源:https://stackoverflow.com/questions/41169357/hive-jdbc-error-java-lang-nosuchfielderror-hive-cli-service-protocol-v7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!