[英]jdbcTemplate.update(String sql) is behaving oddly
Trying to understand jdbcTemplate.update(String sql) which is behaving oddly. 试图理解行为奇怪的jdbcTemplate.update(String sql)。
I have one method: 我有一个方法:
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;
}
My table structure is: 我的表结构是:
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)
Now the issue is: After the execution of this method, data is not coming into DB table. 现在的问题是:执行此方法后,数据不会进入DB表。 I tried to debug and pointer is showing the value of resultsReturned as 1 which means query is executed. 我试图调试,指针显示resultsReturned的值为1,这意味着执行查询。 I don't understand now that what is wrong here. 我现在不明白这里有什么问题。
How should I proceed now? 我现在该怎么办? I tried to run sql query manually and its fine when I run it manually but its not executing from "jdbcTemplate.update(sql)" method. 我尝试手动运行sql查询,当我手动运行它但它没有从“jdbcTemplate.update(sql)”方法执行时它很好。
Thanks Nilesh and Maciej Kowalski for the hint. 感谢Nilesh和Maciej Kowalski的暗示。 My autocommit was off actually. 我的自动提交实际上已经关闭了。 Adding @Transactional
annotation worked for me. 添加@Transactional
注释对我@Transactional
。
@Transactional(value="transactionManager_iwpro_imp", rollbackFor = Exception.class)
public int insertStartSyncDate() {
// ......
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.