java.sql.SQLException: Parameter index out of range (5 > number of parameters, which is 4).

问题描述:

启动项目调接口的时候控制台报错
Cause: java.sql.SQLException: Parameter index out of range (5 > number of parameters, which is 4).

原因分析:

可以看到控制台日志输出了下面这一句话
### The error occurred while setting parameters

很好理解,注入参数的时候发生错误,那肯定就是自己写的sql有问题了,而且是参数绑定类型的错误


解决方案:

修改sql语句,一定要有选择的更新,对于null值的字段不更新,精准更改,这样就不会出错了

<update id="updateByPrimaryKeySelective" parameterType="com.wzh.atcrowdfunding.entity.Admin" >
    update t_admin
    <set >
      <if test="loginAcct != null" >
        login_acct = #{loginAcct,jdbcType=VARCHAR},
      if>
      <if test="userPswd != null" >
        user_pswd = #{userPswd,jdbcType=CHAR},
      if>
      <if test="userName != null" >
        user_name = #{userName,jdbcType=VARCHAR},
      if>
      <if test="email != null" >
        email = #{email,jdbcType=VARCHAR},
      if>
      <if test="createTime != null" >
        create_time = #{createTime,jdbcType=CHAR},
      if>
    set>
    where id = #{id,jdbcType=INTEGER}
  update>

还要注意,sql语句标签内不要有注释的地方,否则也会引起报错

你可能感兴趣的:(error,java,mysql,mybatis,sql,数据库)