在 Java 客户端中,我试图对 Hive 中的表执行查询。执行查询时,程序抛出java.lang.ClassNotFoundException
如下详述。我hadoop-core-1.0.4.jar
在我的类路径中。Hive 版本是 0.12.0,hadoop 版本是 1.0.4。我无法解决问题。会是什么呢?下面是代码片段和错误。
public static String getDummyData() {
String result = "";
String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
log.error("Could not find driver", e);
}
try {
Connection conn = DriverManager.getConnection("jdbc:hive://noon102:10000/default", "","");
String tableName = "user";
String query = "select * from " + tableName + " where id = ?";
PreparedStatement ipMacSt = conn.prepareStatement(query);
ipMacSt.setInt(1, 6);
ResultSet res = ipMacSt.executeQuery();
while (res.next()) {
result = result + res.getString(2) + "\n";
}
} catch (Exception e) {
log.error("Could not execute the query", e);
}
return result;
}
Caused by: java.lang.NoClassDefFoundError: org/apache/hadoop/io/Writable
at org.apache.hadoop.hive.jdbc.HiveQueryResultSet.initSerde(HiveQueryResultSet.java:101)
at org.apache.hadoop.hive.jdbc.HiveQueryResultSet.<init>(HiveQueryResultSet.java:66)
at org.apache.hadoop.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:198)
at org.apache.hadoop.hive.jdbc.HiveStatement.execute(HiveStatement.java:132)
at org.apache.hadoop.hive.jdbc.HiveConnection.configureConnection(HiveConnection.java:133)
at org.apache.hadoop.hive.jdbc.HiveConnection.<init>(HiveConnection.java:122)
at org.apache.hadoop.hive.jdbc.HiveDriver.connect(HiveDriver.java:106)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at com.**.services.HadoopOperations.getDummyData(HadoopOperations.java:90)
... 15 more
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.io.Writable
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 25 more