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?
答案 0 :(得分:2)
新版本的hive-jdbc无法与hiveserver2一起使用。在hive jira上已经有相同的错误。 https://issues.apache.org/jira/browse/HIVE-6050您可以使用hive-jdbc 1.0.0版本,它是兼容的。
答案 1 :(得分:0)
“HIVE_CLI_SERVICE_PROTOCOL_V8”此字段在hive 1.1.0版本中可用。
你需要在classpath中添加hive-jdbc-1.1.0.jar jar。
我希望你的问题得到解决。