jdbcTemplateObject.batchUpdate() 引发了一个 TransientDataAccessResourceException 异常,参数索引超出了范围(4 > 3)
P粉256487077
P粉256487077 2023-09-12 19:32:31
0
1
342

使用Java 1.8Spring Framework 4.0.3-RELEASE,我试图从外部源获取值后将一行插入到MySQL数据库中。

尝试这样做:

private static JdbcTemplate jdbcTemplateObject = null;
private static final String INSERT_QUERY = "insert into order_table(id,order_id,created_time,updated_time)VALUES(?,?,now(),now())";

parseFeedAndStoreIntoDB() {
    List<Object[]> insertData = new ArrayList<>();
    SqlRowSet sqlRowSet = null;

    // id, order_id, created_time, updated_time有值
    insertData.add(new Object[] {id, order_id, created_time, updated_time});
    if (insertData.size() > 0) {
        // 这里出错了
        jdbcTemplateObject.batchUpdate(INSERT_QUERY, insertData);
    }
}

当我运行这个方法时,我得到以下异常:

Exception in parseFeedAndStoreIntoDB() method
org.springframework.dao.TransientDataAccessResourceException: PreparedStatementCallback; SQL 
[insert into order_table(id,order_id,created_time,updated_time)VALUES(?,?,now(), now());]; Parameter index out of range (4 > 3).; nested exception is java.sql.SQLException: 
Parameter index out of range (4 > 3).

我已经计算了行数,我的Java代码和我创建的MySQL数据库表中都有4行。

P粉256487077
P粉256487077

最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!