2

I need to connect Hive2 and retrive information from it. I am using apache HiveServer2 client to connect to Hive, in POM:

<dependency>
    <groupId>org.apache.hive</groupId>
    <artifactId>hive-jdbc</artifactId>
    <version>1.2.1</version>
</dependency>

The code is:

public class HiveJdbcClient {
    private static String driverName = "org.apache.hive.jdbc.HiveDriver";
    public static void main(String[] args) throws SQLException {
        org.apache.log4j.BasicConfigurator.configure(new NullAppender());
         try {
              Class.forName(driverName);
            } catch (ClassNotFoundException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
              System.exit(1);
            }

         Connection con = DriverManager.getConnection("jdbc:hive2://xxx.xx.xx.xx:21050/;auth=noSasl");
         Statement stmt = con.createStatement();
         ResultSet res = stmt.executeQuery("show tables");
            if (res.next()) {
              System.out.println(res.getString(1));
            }
    }

}

But when running this app, I got this exeception:

Exception in thread "main" java.lang.NoSuchFieldError: HIVE_CLI_SERVICE_PROTOCOL_V8
    at org.apache.hive.jdbc.HiveConnection.<init>(HiveConnection.java:189)
    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:270)
    at org.springframework.samples.hadoop.hive.HiveJdbcClient.main(HiveJdbcClient.java:23)

Can anyone tell me how this exception is thrown?

user3006967
  • 3,291
  • 10
  • 47
  • 72
  • Check the version of the dependent jars that you used in the program and its compatibility with the hive version – Amal G Jose Jul 28 '15 at 18:46

2 Answers2

2

The new version of hive-jdbc is not working with hiveserver2. There is already a bug opened for the same on hive jira. https://issues.apache.org/jira/browse/HIVE-6050 You can use hive-jdbc 1.0.0 version, It is compatible.

Adam
  • 28,537
  • 15
  • 60
  • 73
Reena Upadhyay
  • 1,977
  • 20
  • 35
0

"HIVE_CLI_SERVICE_PROTOCOL_V8" this field is available in hive 1.1.0 version.

you need to add hive-jdbc-1.1.0.jar jar in classpath.

I hope your problem would get resolved.

Balkrushna Patil
  • 418
  • 6
  • 12