我无法理解ORA-01722背后的原因:无效数字

use*_*344 6 java oracle jdbc prepared-statement ora-01722

我有一个随机生成的问题(在千分之一的通话之间).错误ORA-01722:准备语句Oracle数据库中执行sql update时,以随机方式生成错误的数字.案例详情如下:

try {
        connection = getConnection();
        statement = connection.prepareStatement(sql);
        for (int i = 0; i < params.length; i++) {
            if (params[i] instanceof Date) {
                statement.setTimestamp(i + 1, new Timestamp(((Date) params[i]).getTime()));
            } else if (params[i] instanceof java.util.Date) {
                statement.setTimestamp(i + 1, new Timestamp(((java.util.Date) params[i]).getTime()));
            } else {
                statement.setObject(i + 1, params[i]);
            }
            paramsBuilder.append(": " + params[i]);
        }
        if (logger.isInfoEnabled()) {
            logger.info("Query String  [" + sql + "] [" + paramsBuilder + "]");
            logger.info("Query Parameters [" + paramsBuilder + "]");
        }
        result = statement.executeUpdate();
        if (logger.isInfoEnabled()) {
            logger.info(result + " rows affected");
        }
    } catch (SQLException e) {
        if (logger.isInfoEnabled()) {
            String message = "Failed to execute SQL statment [" + sql + "] with parameters [" + paramsBuilder + "]";
            logger.error(message, e);
        }
        throw new DAOException(e);
    }
Run Code Online (Sandbox Code Playgroud)

并且log中的值是这样的:

Failed to execute SQL statment [update CUSTOMER_CASE set no_of_ptp=?, no_of_unreached=?,collector_name=? , last_case_status_history_id=?, current_handler=?, handling_start_time=?,due_total_open_amount=?, payment_due_invoice_id =?  where id=?] with parameters [: 0: 0: auto: 5470508: null: null: 0.0: 23410984: 2476739] java.sql.SQLException: ORA-01722: invalid number
Run Code Online (Sandbox Code Playgroud)

通过在DB处跟踪查询参数,所有参数都通过JDBC驱动程序正确传输,除了参数23410984,它被值替换"<C4>^X* U"(注意此值包含在char'u '之前的回车!).我不知道为什么

小智 5

关键原因是java.sql.SQLException: ORA-01722: invalid number.
可能是字段last_case_status_history_id类型是数字,但您的参数为null