【问题标题】:java stored procedure cause ORA-00911: invalid characterjava存储过程导致ORA-00911:无效字符
【发布时间】:2014-07-14 13:51:40
【问题描述】:

我尝试在以下类中调用存储过程,这会导致“ORA-00911:无效字符”,但我找不到无效字符在哪里,所有事情对我来说似乎都很好,因为我遵循了存储过程示例。

public Info inquireData(String str)
         {
    Info result = new QuotaInfo();
    Connection con = null;
    CallableStatement callableStatement = null;
    try {
        con = (Connection) getEntityManager().unwrap(Connection.class);
        callableStatement = con.prepareCall("{ call WEB_DATA_INQUIRY(?,?,?,?,?,?) }");

        result = new Info();

        callableStatement.setString(1, str);
        callableStatement.registerOutParameter(2, Types.NUMERIC);
        callableStatement.registerOutParameter(3, Types.NUMERIC);
        callableStatement.registerOutParameter(4, Types.DATE);
        callableStatement.registerOutParameter(5, Types.NUMERIC);
        callableStatement.registerOutParameter(6, Types.VARCHAR);

        callableStatement.execute();


        result.setTotalNumber(callableStatement.getInt(2));
        result.setConsumedNumber(callableStatement.getInt(3));
        Date expiryDate = callableStatement.getDate(4);
        if (expiryDate != null) {
            result.setExpiryDate(new java.util.Date(expiryDate.getTime()));
        }

    } catch (SQLException e) {
        throw new DBException(e);
    }

    return result;

}

当我运行程序时,异常显示如下:

com.walsa.web.dalayer.exception.DBException: java.sql.SQLSyntaxErrorException:    ORA-00911: invalid character
 ORA-06512: at "WALSA.WEB_DATA_INQUIRY", line 12
 ORA-06512: at line 1

【问题讨论】:

  • 您的 proc 中有一些 Dynamic SQL,这就是造成这种情况的原因。堆栈跟踪也是如此。(第 12 行)。像这样的Exceptions应该被捕获在过程内部,并且应该将适当的消息返回给调用者。(JDBC
  • 所以你的意思是这段代码是完全正确的?
  • 是的,你的callable语句成功了,只有proc抛出了一个SQL异常

标签: java sql oracle stored-procedures


【解决方案1】:

一段时间后,我们发现 java 代码正确连接到该存储过程。问题出在存储过程本身。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-10
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-18
    相关资源
    最近更新 更多