jdbcTemplate.update(String sql) 行为异常

jdbcTemplate.update(String sql) is behaving oddly

试图理解表现异常的 jdbcTemplate.update(String sql)。

我有一个方法:

public int insertStartSyncDate() {
    String sql = "INSERT INTO iwpro_imp."+jobStatusTable+" (job_name,status,start_time,comment) VALUES ('sswltimport', 'running', NOW(), 'Just started.')";
    int resultsReturned = 0;
    try{
        resultsReturned = jdbcTemplate.update(sql);
    }catch(Exception e){
        e.printStackTrace();
    }
    return resultsReturned;
}

我的table结构是:

mysql> desc import_job_status;
+------------+------------------------------------+------+-----+-------------------+----------------+
| Field      | Type                               | Null | Key | Default           | Extra          |
+------------+------------------------------------+------+-----+-------------------+----------------+
| job_id     | bigint(20) unsigned                | NO   | PRI | NULL              | auto_increment |
| job_name   | varchar(20)                        | NO   | MUL | NULL              |                |
| status     | enum('running','success','failed') | NO   | MUL | running           |                |
| start_time | timestamp                          | NO   | MUL | CURRENT_TIMESTAMP |                |
| end_time   | timestamp                          | YES  | MUL | NULL              |                |
| comment    | text                               | YES  |     | NULL              |                |
+------------+------------------------------------+------+-----+-------------------+----------------+
6 rows in set (0.00 sec)

现在的问题是: 执行此方法后,数据不会进入 DB table。我尝试调试,指针将 resultsReturned 的值显示为 1,这意味着查询已执行。我现在不明白这里有什么问题。

我现在应该如何进行?我尝试 运行 sql 手动查询,当我 运行 手动查询时它很好,但它不是从 "jdbcTemplate.update(sql)" 方法执行的。

感谢 Nilesh 和 Maciej Kowalski 的提示。 我的自动提交实际上是关闭的。添加 @Transactional 注释对我有用。

@Transactional(value="transactionManager_iwpro_imp", rollbackFor = Exception.class)
    public int insertStartSyncDate() {
 // ......
}