pcs110
pcs110
采纳率50%
2017-03-20 09:40 阅读 4.4k

MYBATIS 批量update 报错的问题

批量update,很简单的sql语句,可是一直在报错。不知道为什么,求助!!!

close="" separator=";">
update student_point_level s
set s.score = #{item.score}
where s.id = #{item.id}


按照打印出来的sql,贴到front里运行的也都是对的....

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 student_point_level s

        set s.score = 16
        where s.id = 19' at line 7

The error may involve com.supert.st.dao.StudentPointLevelMapper.updateStudentPointLevelBatch-Inline

The error occurred while setting parameters

SQL: update student_point_level s set s.score = ? where s.id = ? ; update student_point_level s set s.score = ? where s.id = ?

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 student_point_level s

        set s.score = 16
        where s.id = 19' at line 7

; bad SQL grammar []; nested exception is 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 student_point_level s
set s.score = 16
where s.id = 19' at line 7

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

4条回答 默认 最新

  • 已采纳
    pcs110 pcs110 2017-03-21 03:33

    经过朋友的帮助,此问题已经解决。
    参考:http://www.cnblogs.com/hyq0002013/p/6077847.html

    点赞 评论 复制链接分享
  • lin_xi_ Bruce_Lau_ 2017-03-20 09:53

    把你的xml里面的sql全部贴上来看看

    点赞 评论 复制链接分享
  • pcs110 pcs110 2017-03-20 10:01

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >







    <update id="updateStudentPointLevelBatch" parameterType="java.util.List">
        <foreach collection="list" item="item" index="index" open=""
            close=";" separator=";">
            update student_point_level s
            set s.score = #{item.score}
            where s.id = #{item.id} 
        </foreach>
    </update>
    
    <insert id="insertStudentPointLevelBatch">
        insert into STUDENT_POINT_LEVEL(POINT_ID,STUDENT_ID,SCORE,DATETIME)
        values
        <foreach collection="list" item="item" index="index"  separator="," >  
             (#{item.pointId},#{item.studentId},#{item.score},now()) 
        </foreach> 
    </insert>
    

    点赞 评论 复制链接分享
  • lin_xi_ Bruce_Lau_ 2017-03-20 10:11

    图片说明

    点赞 评论 复制链接分享

相关推荐