StringIndexOutOfBoundsException: String index out of range: 458

Error message:

org.springframework.dao.TransientDataAccessResourceException:
### Error updating database. Cause: java.sql.SQLException: java.lang.StringIndexOutOfBoundsException: String index out of range: 458
...
...
...

problem causes:

 <insert id="batchInsert" parameterType="java.util.List" >
    insert into table_name (省略...)
    values
    <foreach collection="list" index="index" item="item" open="" separator="," close="">
      (
        省略...
      )
    </foreach>
  </insert>

<update id="batchUpdate" parameterType="xxx" >
   <foreach collection="list" index="index" item="item" open="" separator=";" close="">
        (
             update table_name set xxxx = #{xx,jdbcType=INTEGER}... where ...
                      省略...
        )
   </foreach>
   
  </update>

When calling a batch insert or update operation, if list is null or size()==0, this error will occur.

solution:

Before calling the batch operation, determine whether the list is null or size()==0. If so, the batch operation will not be called.

Guess you like

Origin blog.csdn.net/bingxuesiyang/article/details/132411690