我需要连接 Hive2 并从中检索信息。我在 POM 中使用 apache HiveServer2 客户端连接到 Hive:
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>1.2.1</version>
</dependency>
代码是:
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));
}
}
}
但是在运行这个应用程序时,我得到了这个异常:
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)
谁能告诉我这个异常是怎么抛出的?