我正在使用 Cloudera Manager 在集群设置中使用 CDH 4.2.1-1.cdh4.2.1.p0.5,并且我正在尝试使用 Java 中的 Hive API 使 Hive 示例工作。我使用的配置单元版本是 0.10 (hive-hwi-0.10.0-cdh4.2.1.jar),我正在尝试按照以下网址中的说明设置一个简单的示例:https ://cwiki.apache.org/confluence /display/Hive/HiveClient
运行我的代码(帖子末尾的源代码)时,我收到以下错误:
Exception in thread "main" java.sql.SQLException: org.apache.thrift.TApplicationException: Invalid method name: 'execute'
at org.apache.hadoop.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:191)
at org.apache.hadoop.hive.jdbc.HiveStatement.execute(HiveStatement.java:127)
at org.apache.hadoop.hive.jdbc.HiveConnection.configureConnection(HiveConnection.java:126)
at org.apache.hadoop.hive.jdbc.HiveConnection.<init>(HiveConnection.java:121)
at org.apache.hadoop.hive.jdbc.HiveDriver.connect(HiveDriver.java:104)
at java.sql.DriverManager.getConnection(DriverManager.java:579)
at java.sql.DriverManager.getConnection(DriverManager.java:221)
我已经在 Google 中搜索了一段时间,但找不到任何解决此问题的方法。任何人都可以给我一个提示可能导致问题的原因?
提前致谢,
罗比
导致错误的代码:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.log4j.Logger;
public class HiveJob {
private static Logger mLogger = Logger.getLogger(HiveJob.class);
private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
public static void main(String[] args) throws SQLException {
HiveJob myJob = new HiveJob();
myJob.execute();
}
public void execute() throws SQLException {
mLogger.info("Start HiveJob");
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(1);
}
Connection con = DriverManager.getConnection("jdbc:hive://myHiveServer:9083/default", "", "");
Statement stmt = con.createStatement();
String sql = "SHOW TABLES";
System.out.println("Running: " + sql);
ResultSet res = stmt.executeQuery(sql);
while (res.next()) {
System.out.println(res.getString(1));
}
mLogger.info("HiveJob executed!");
}
}