Hive 2 JDBC PreparedStatement引发错误,无法识别“?"附近的输入'< EOF>' “< EOF>"在表达规范中 [英] Hive 2 JDBC PreparedStatement throws an error cannot recognize input near '?' '<EOF>' '<EOF>' in expression specification

查看:708
本文介绍了Hive 2 JDBC PreparedStatement引发错误,无法识别“?"附近的输入'< EOF>' “< EOF>"在表达规范中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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表,其中包含String类型的列spd_field_label_id和SUBJECT_USER_ID.

RAL is a simple Hive table with String type columns spd_field_label_id and SUBJECT_USER_ID.

使用Hive2的简单PreparedStatement,在下面抛出一个错误stacktrace.关于可能出什么问题的任何指示?使用Statement而不是PreparedStatement且不使用?时,相同的查询工作正常.用于参数绑定.

Simple PreparedStatement using Hive2 throwing an Error stacktrace below. Any pointers on what could be wrong? Same query works fine when using Statement instead of PreparedStatement and without using ? for parameter binding.

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);

您使用了错误的方法.您已经准备好对帐单.准备执行.应该是:

You're using the wrong method. You've already prepared the statement. It is ready to execute. It should be:

stmt.execute();

这篇关于Hive 2 JDBC PreparedStatement引发错误,无法识别“?"附近的输入'&lt; EOF&gt;' “&lt; EOF&gt;"在表达规范中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆