前景提要
HDC调试需求开发(15万预算),能者速来!>>>
使用mybatis批量更新数据,用mybatis操作一直报错,但是把日志里的sql语句复制出来,就可以执行.
另外,如果我只传一个对象过来,是可以操作成功的.如果传2个对象就报下面这个错误.
xml配置文件:
<update id="updateList" parameterType="list">
<foreach collection="list" item="item" index="index" open="" close="" separator=";">
update v_compress_video
<set>
<if test="null != #{item.taskId}">task_id = ${item.taskId}</if>
<if test="null != #{item.videoName}">,video_name = ${item.videoName}</if>
<if test="null != #{item.videoPath}">,video_path = ${item.videoPath}</if>
<if test="null != #{item.rstpDriver}">,rstp_driver = ${item.rstpDriver}</if>
<if test="null != #{item.rstpIp}">,rstp_ip = ${item.rstpIp}</if>
<if test="null != #{item.rstpPort}">,rstp_port = ${item.rstpPort}</if>
<if test="null != #{item.rstpAccount}">,rstp_account = ${item.rstpAccount}</if>
<if test="null != #{item.rstpPwd}">,rstp_pwd = ${item.rstpPwd}</if>
<if test="null != #{item.status}">,status = ${item.status}</if>
</set>
<where>
id = ${item.id}
</where>
</foreach>
</update>
错误信息:
2016-09-27 19:35:46,904 [DEBUG]:[org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:85)] JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@6a8c256f] will be managed by Spring
2016-09-27 19:35:46,904 [DEBUG]:[org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:132)] ooo Using Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@6a8c256f]
2016-09-27 19:35:46,919 [DEBUG]:[org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:132)] ==> Preparing: update v_compress_video SET task_id = 3812808338727632896 ,video_name = 'vName1' ,video_path = 'vPath1' ,rstp_driver = 'vDriver1' ,rstp_ip = 'vIP1' ,rstp_port = 'vPort1' ,rstp_account = 'vAccount1' ,rstp_pwd = 'vPwd1' ,status = 1 WHERE id = 3812808338790547456 ; update v_compress_video SET task_id = 3812808338727632896 ,video_name = 'vName2' ,video_path = 'vPath2' ,rstp_driver = 'vDriver2' ,rstp_ip = 'vIP2' ,rstp_port = 'vPort2' ,rstp_account = 'vAccount2' ,rstp_pwd = 'vPwd2' ,status = 1 WHERE id = 3812808338857656320
2016-09-27 19:35:46,919 [DEBUG]:[org.apache.ibatis.logging.jdbc.BaseJdbcLogger.debug(BaseJdbcLogger.java:132)] ==> Parameters:
2016-09-27 19:35:46,919 [DEBUG]:[org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.logTranslation(SQLErrorCodeSQLExceptionTranslator.java:397)] Translating SQLException with SQL state '42000', error code '1064', message [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'update v_compress_video
SET task_id = 3812808338727632896
,video_name =' at line 13]; SQL was [] for task [
### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'update v_compress_video
SET task_id = 3812808338727632896
,video_name =' at line 13
### The error may involve com.zhixin.dao.compress.impl.CompressVideoDaoImpl.updateList-Inline
### The error occurred while setting parameters
### SQL: update v_compress_video SET task_id = 3812808338727632896 ,video_name = 'vName1' ,video_path = 'vPath1' ,rstp_driver = 'vDriver1' ,rstp_ip = 'vIP1' ,rstp_port = 'vPort1' ,rstp_account = 'vAccount1' ,rstp_pwd = 'vPwd1' ,status = 1 WHERE id = 3812808338790547456 ; update v_compress_video SET task_id = 3812808338727632896 ,video_name = 'vName2' ,video_path = 'vPath2' ,rstp_driver = 'vDriver2' ,rstp_ip = 'vIP2' ,rstp_port = 'vPort2' ,rstp_account = 'vAccount2' ,rstp_pwd = 'vPwd2' ,status = 1 WHERE id = 3812808338857656320
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'update v_compress_video
SET task_id = 3812808338727632896
,video_name =' at line 13
日志里面复制出来的sql
UPDATE
v_compress_video
SET
task_id = 3812808338727632896,
video_name = 'vName1',
video_path = 'vPath1',
rstp_driver = 'vDriver1',
rstp_ip = 'vIP1',
rstp_port = 'vPort1',
rstp_account = 'vAccount1',
rstp_pwd = 'vPwd1',
STATUS = 1
WHERE id = 3812808338790547456 ;
UPDATE
v_compress_video
SET
task_id = 3812808338727632896,
video_name = 'vName2',
video_path = 'vPath2',
rstp_driver = 'vDriver2',
rstp_ip = 'vIP2',
rstp_port = 'vPort2',
rstp_account = 'vAccount2',
rstp_pwd = 'vPwd2',
STATUS = 1
WHERE id = 3812808338857656320
数据库信息
Create Table
CREATE TABLE `v_compress_video` (
`id` bigint(20) NOT NULL COMMENT '主键',
`task_id` bigint(20) NOT NULL COMMENT '任务id',
`video_name` varchar(50) DEFAULT NULL COMMENT '视频名称',
`video_path` varchar(100) DEFAULT NULL COMMENT '视频文件存放地址;视频文件使用',
`rstp_driver` varchar(20) DEFAULT NULL COMMENT '实时视频驱动类型;',
`rstp_ip` varchar(32) DEFAULT NULL COMMENT '实时视频ip',
`rstp_port` varchar(10) DEFAULT NULL COMMENT '实时视频端口',
`rstp_account` varchar(20) DEFAULT NULL COMMENT '实时视频登录账号',
`rstp_pwd` varchar(20) DEFAULT NULL COMMENT '实时视频登录密码',
`status` int(2) DEFAULT NULL COMMENT '状态',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='视频浓缩&压缩任务关联视频表'