oracle SQL 命令未正确结束

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7368073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 00:18:27  来源:igfitidea点击:

SQL Command not properly Ended

javasqloraclejdbc

提问by sng

Tried running a java method that runs this oracle SQL query

尝试运行运行此 oracle SQL 查询的 java 方法

String query =
            "SELECT count(*) " +
            "FROM TASK t " +
            "WHERE t.TASK_ID = ? ";

I keep getting SQL Command not properly Ended

我不断收到 SQL 命令未正确结束

Printed the string and got this output SELECT count(*) FROM TASK t WHERE t.TASK_ID = ?

打印字符串并得到这个输出 SELECT count(*) FROM TASK t WHERE t.TASK_ID = ?

*edited to reflect new changes, the method basically looks for the taskID and if it exists return true, otherwise false.

*编辑以反映新的变化,该方法基本上查找taskID,如果存在则返回true,否则返回false。

public boolean loadTaskId(Integer taskId) throws SQLException{

    int count = 0;

    String query =
            "SELECT count(*) " +
            "FROM TASK t " +
            "WHERE t.TASK_ID = ?";

    OraclePreparedStatement stmt = prepareStatement(query);
    stmt.setInt(1, taskId);
    ResultSet rs = stmt.executeQuery();
    if (rs.next()) { // only load the first one
        count = rs.getInt(1);
    }
    stmt.close();
    if ( count == 0) {
        return false;
    } else {
        return true;
    }
}

采纳答案by sng

Figured out whats wrong, I didn't delete the .jar file in the library and it had some name conflicts going on and wasn't rebuilding. *slaps my own head

弄清楚出了什么问题,我没有删除库中的 .jar 文件,它发生了一些名称冲突并且没有重建。*打我自己的头

回答by JW8

You might want to modify your SQL statement to include some spaces:

您可能希望修改 SQL 语句以包含一些空格:

String query =
        "SELECT count(*) " +
        "FROM TASK t " +
        "WHERE t.TASK_ID = ?";

That's probably the problem. You can print the string out to System.out to confirm.

这大概就是问题所在。您可以将字符串打印到 System.out 进行确认。

回答by Anush

String query =
            "SELECT count(*) " +
            "FROM TASK t " +
            "WHERE t.TASK_ID = ?";

You did not add spaces

你没有添加空格