gpt4 book ai didi

java - Hive 2 JDBCPreparedStatement 抛出错误无法识别表达式规范中 '?' '' '' 附近的输入

转载 作者:行者123 更新时间:2023-12-02 12:06:43 27 4
gpt4 key购买 nike

try {
Class.forName("org.apache.hive.jdbc.HiveDriver");
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(1);
}
String query = "SELECT spd_field_label_id FROM RAL WHERE SUBJECT_USER_ID = ?";

PreparedStatement stmt = null;
Connection con = null;
boolean testCasePassed = false;

try {

con = DriverManager.getConnection("jdbc:hive2://localhost:10000/default", "", "");
stmt = con.prepareStatement(query);

stmt.setString(1, "USR-44");
ResultSet resultSet = stmt.executeQuery(query);

Assert.assertNotNull(resultSet);

while (resultSet.next()) {
testCasePassed = true;
System.out.println("=======Test =========" + resultSet.getString("spd_field_label_id"));
}
} finally {

if (stmt != null) {
stmt.close();
}

if (con != null) {
con.close();
}

}

return testCasePassed;

RAL 是一个简单的 Hive 表,具有字符串类型列 spd_field_label_id 和 SUBJECT_USER_ID。

使用 Hive2 的简单PreparedStatement 抛出下面的错误堆栈跟踪。有什么可能出问题的指示吗?当使用Statement而不是PreparedStatement并且不使用?时,相同的查询可以正常工作。用于参数绑定(bind)。

org.apache.hive.service.cli.HiveSQLException: Error while compiling statement: FAILED: ParseException line 1:62 cannot recognize input near '?' '<EOF>' '<EOF>' in expression specification
at org.apache.hive.jdbc.Utils.verifySuccess(Utils.java:264)
at org.apache.hive.jdbc.Utils.verifySuccessWithInfo(Utils.java:250)
at org.apache.hive.jdbc.HiveStatement.runAsyncOnServer(HiveStatement.java:309)
at org.apache.hive.jdbc.HiveStatement.execute(HiveStatement.java:250)
at org.apache.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:434)

最佳答案

stmt.executeQuery(query);

您使用了错误的方法。你已经准备好了声明。它已准备好执行。应该是:

stmt.execute();

关于java - Hive 2 JDBCPreparedStatement 抛出错误无法识别表达式规范中 '?' '<EOF>' '<EOF>' 附近的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46859270/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com