我是 Hive 和 Hadoop 的新手。在我的教程中,我想将表创建为
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.DriverManager;
public class HiveCreateDb {
private static String driverName = "org.apache.hive.jdbc.HiveDriver";
public static void main(String[] args) {
// Register driver and create driver instance
try {
Class.forName(driverName);
// get connection
Connection con = DriverManager.getConnection("jdbc:hive2://localhost:10000/mydb", "root", "");
Statement stmt = con.createStatement();
stmt.executeQuery("CREATE TABLE IF NOT EXISTS " + " employee ( e_id int, name String, "
+ " salary String)" + " STORED AS TEXTFILE");
System.out.println("Operation done successfully.");
con.close();
} catch (ClassNotFoundException e) {
System.err.println("class not found!!!!");
e.printStackTrace();
} catch (SQLException e) {
System.err.println("sql exception!!!");
e.printStackTrace();
}
}
}
当我运行代码时出现此错误
sql exception!!! java.sql.SQLException: The query did not generate a result set! at org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:393)
at tr.com.vedat.hive.HiveCreateDb.main(HiveCreateDb.java:25)
所以,我找不到解决方案。谁能帮助我找到错误并引导我正确的方法?
看起来 Hive 驱动程序随着时间的推移而发生了变化,并且随着时间的推移变得更加严格。看到这个谷歌小组讨论 https://groups.google.com/a/cloudera.org/forum/#!topic/cdh-user/EZe5z7HXJb4
Use stmt.execute()
用于创建新表的查询。的执行查询。这executeQuery()
现在仅适用于选择查询 (DML),而执行可能适用于 DDL(数据定义)。
这是有道理的,因为我在其他语言中见过的大多数驱动程序(在我的例子中是 Python 和 C#)会将只读操作与实际可以更改数据结构的方法分开。
This 页面显示了executeQuery()的用法 http://docs.hortonworks.com/HDPDocuments/HDP1/HDP-1.2.4/ds_Hive/hiveclient.html对于 DDL:
ResultSet res = stmt.executeQuery("create table " + tableName + " (key int, value string)");
的例子execute
这里是Python,所以你可以注意到Java示例中的所有DDL都使用executeQuery
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)