【问题标题】:Invalid SQL statement with CallableStatement during Stored proc call在存储过程调用期间使用 CallableStatement 的 SQL 语句无效
【发布时间】:2020-04-07 15:43:42
【问题描述】:

我有下面的代码来调用带有某些参数的存储过程。

但是它在callableStatement.execute(); 上失败并出现错误:

java.sql.SQLSyntaxErrorException: ORA-00900: invalid SQL statement

public void setContext(String userId, String someId, List<String> accountsList) {
        List<SqlParameter> parameters = Collections.singletonList(new SqlInOutParameter("output", Types.VARCHAR));
        log.info("executing stored procedure with user id: {}", userId);
        Map<String, Object> t =  defaultTemplate.call(connection -> {
            CallableStatement callableStatement = connection.prepareCall("STORED_PROC(?, ?, ?, ?)");
            callableStatement.setString(1, userId);
            callableStatement.registerOutParameter(2, Types.VARCHAR);
            callableStatement.setString(3, someId);
            OracleConnection oracleConnection = connection.unwrap(OracleConnection.class);
            Array array = oracleConnection.createOracleArray("SOME_TYPE", accountsList.toArray());
            callableStatement.setArray(4, array);
            callableStatement.execute();
            return callableStatement;
        }, parameters);
        log.info("Status of the stored procedure: {}", t.get("status_output"));
 }

我做错了什么?

【问题讨论】:

  • 检查下面的陈述是否正确

标签: java sql oracle stored-procedures


【解决方案1】:

你可以在调用你的过程时写call语句

CallableStatement callableStatement = connection.prepareCall("{call STORED_PROC(?, ?, ?, ?)}");

【讨论】:

    【解决方案2】:
    CallableStatement callableStatement = connection.prepareCall("STORED_PROC(?, ?, ?, ?)");
    

    {}放在参数周围。并在语句之前添加调用。如下所示:

    CallableStatement callableStatement = connection.prepareCall("{call STORED_PROC(?, ?, ?, ?)}");
    

    【讨论】:

    • 是的,我错过了“呼叫关键字”。这个是正确的。
    • @Plainsage 提供您的存储过程,以便我们更好地了解。
    • @Ergi Nushi stored_proc(userId in varchar2, sid in out varchar2, someId in varchar2, v_acct_list in some_type, v_keep_forever in char default 'N');这是存储过程签名
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-26
    • 1970-01-01
    相关资源
    最近更新 更多