ORA-01008:使用JdbcTempate时并非所有变量都绑定

时间:2017-09-13 13:51:35

标签: spring oracle

我正在使用jdbcTemplate版本4运行一个简单的插入并获取:

ORA-01008: not all variables bound

这里是插入:

    int[] ret = jdbcTemplate.batchUpdate("INSERT INTO BATCH_JOBS_TABLE (JOB_STATUS, CREATE_BY) VALUES (?,?)", "ACTIVE","USER_ADMIN");

堆栈跟踪:

Caused by: java.sql.BatchUpdateException: error occurred during batching: ORA-01008: not all variables bound

    at oracle.jdbc.driver.OracleStatement.executeBatch(OracleStatement.java:5043)
    at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:246)
    at org.springframework.jdbc.core.JdbcTemplate$1BatchUpdateStatementCallback.doInStatement(JdbcTemplate.java:561)
    at org.springframework.jdbc.core.JdbcTemplate$1BatchUpdateStatementCallback.doInStatement(JdbcTemplate.java:548)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:408)
    ... 4 more

1 个答案:

答案 0 :(得分:1)

int[] ret = jdbcTemplate.batchUpdate("INSERT INTO BATCH_JOBS_TABLE (JOB_STATUS, CREATE_BY) VALUES (?,?)", "ACTIVE","USER_ADMIN");

调用的最后两个参数应该是SQL。

来自javadoc

/**
 * Issue multiple SQL updates on a single JDBC Statement using batching.
 * <p>Will fall back to separate updates on a single Statement if the JDBC
 * driver does not support batch updates.
 * @param sql defining an array of SQL statements that will be executed.
 * @return an array of the number of rows affected by each statement
 * @throws DataAccessException if there is any problem executing the batch
 */
int[] batchUpdate(String... sql) throws DataAccessException;

因此您需要传递参数,而不仅仅是在通话中添加它们。