赞
踩
当使用mybatis写好了sql运行时,报错部分内容如下
Error updating database. Cause: java.sql.SQLException: Column count doesn't match value count at row 1\r\n### The error may involve com.network.dailyplanner.dao.EventDao.addEvent-Inline\r\n### The error occurred while setting parameters\r\n### SQL: insert into biz_event (title, content, start_time, end_time, remind_time, group_id, remark, show_status, event_status, gmt_create) values ( ?, ? ?, ?, ?, ?, ?, ?, ?, now() )\r\n### Cause: java.sql.SQLException: Column count doesn't match value count at row 1\n; bad SQL grammar []; nested exception is java.sql.SQLException: Column count doesn't match value count at row 1
意思是存储的数据与数据库里的数据个数不一致
经过查看发现是在mybatis的sql映射文件里在添加到数据库中的两个字段之间没有添加逗号
- <insert id="addEvent" parameterType="com.network.dailyplanner.bean.BizEventBean" useGeneratedKeys="true" keyProperty="id">
- insert into biz_event
- (title, content, start_time, end_time, remind_time, group_id, remark, show_status, event_status, gmt_create)
- values
- (
- #{title, jdbcType=VARCHAR},
- #{content, jdbcType=VARCHAR}
- #{startTime, jdbcType=TIMESTAMP},
- #{endTime, jdbcType=TIMESTAMP},
- #{remindTime, jdbcType=TIMESTAMP},
- #{groupId, jdbcType=BIGINT},
- #{remark, jdbcType=VARCHAR},
- #{showStatus, jdbcType=TINYINT},
- #{eventStatus, jdbcType=TINYINT},
- now()
- )
- </insert>

所以就在 #{content, jdbcType=VARCHAR} 一行后面添加了个逗号,然后重新支行,问题得到解决。
以后写代码还是要认真的,遇到问题也要细心分析和查看报错位置代码中的每一个细节是否有误
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。