Data truncation: Truncated incorrect DOUBLE value 解决方案

时间:2022-05-10 11:22:45

  1.情况限制

  此处的错误解决方案只讨论:

    在使用Mybatis时,传入数组且使用<foreach>标签时出现此种报错;

  2.报错案例

   mapper.java

    /**
* @Description: 取消验厂通知
* SupplierCheckfactoryInformMapper
* cancelNotifyToCheckFac
* @param params
* 2016-8-24 下午3:42:44
*/
public void cancelNotifyToCheckFac(
          @Param("regId")Integer regId,
          @Param("updateDt")Date updateDt,
          @Param("supplierIds")BigInteger[] supplierIds
         );

    mapper.xml

<update id="cancelNotifyToCheckFac">
UPDATE
t_supplier_regaccount_info tsri,
t_supplier_checkfactory_inform tsci
SET
status = 2,
update_dt = #{updateDt}
WHERE
tsri.supplier_id = tsci.supplier_id
AND
tsri.supplier_id in
<foreach collection="supplierIds" item="item" index="index" open="(" separator="," close=")">
#{supplierIds}
</foreach>
AND
tsri.reg_id = #{regId}
AND
tsci.status = 0
</update>

    报错信息:

### Error updating database.  Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: '\xAC\xED\x00\x05ur\x00\x17[Ljava.math.BigInteger;\x0E|\xDBF\xE0:`\xC6\x02\x00\x00xp\x00\x00\x00\x01sr\x00\x14java.math.BigIntege'
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: UPDATE t_supplier_regaccount_info tsri, t_supplier_checkfactory_inform tsci SET status = 2, update_dt = ? WHERE tsri.supplier_id = tsci.supplier_id AND tsri.supplier_id in ( ? ) AND tsri.reg_id = ? AND tsci.status = 0
### Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: '\xAC\xED\x00\x05ur\x00\x17[Ljava.math.BigInteger;\x0E|\xDBF\xE0:`\xC6\x02\x00\x00xp\x00\x00\x00\x01sr\x00\x14java.math.BigIntege'
; SQL []; Data truncation: Truncated incorrect DOUBLE value: '\xAC\xED\x00\x05ur\x00\x17[Ljava.math.BigInteger;\x0E|\xDBF\xE0:`\xC6\x02\x00\x00xp\x00\x00\x00\x01sr\x00\x14java.math.BigIntege'; nested exception is com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: '\xAC\xED\x00\x05ur\x00\x17[Ljava.math.BigInteger;\x0E|\xDBF\xE0:`\xC6\x02\x00\x00xp\x00\x00\x00\x01sr\x00\x14java.math.BigIntege'
ERROR 2016-09-18 15:03:17,661 util.web.ExceptionAdvisor: 内部/外部请求人:/admin
ERROR 2016-09-18 15:03:17,661 util.web.ExceptionAdvisor: 请求IP:0:0:0:0:0:0:0:1
ERROR 2016-09-18 15:03:17,662 util.web.ExceptionAdvisor: 请求参数:{supplierId=26};
ERROR 2016-09-18 15:03:17,662 util.web.ExceptionAdvisor: =====service通知结束,继续向上抛BusinessException=====
WARN 2016-09-18 15:03:17,669 org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver: Handler execution resulted in exception
common.model.BusinessException: 抱歉,程序内部错误,操作失败! 请稍后再试或与管理员联系!

    3.错误分析

    此处的报错信息:Data truncation: Truncated incorrect DOUBLE value

      3.1:在网上的主要错误原因是:update语句中的set中出现了and关键字,而应该使用逗号<,>代替之;这里的报错不属于这种情况;

      3.2:此处错误原因为:<foreach>标签中不能使用参数名#{supplierIds},而应该使用#{item},貌似为固定写法;根本原因尚不明确,待大神指点;

    

    4.代码修改后

    mapper.xml

<update id="cancelNotifyToCheckFac">
UPDATE
t_supplier_regaccount_info tsri,
t_supplier_checkfactory_inform tsci
SET
status = 2,
update_dt = #{updateDt}
WHERE
tsri.supplier_id = tsci.supplier_id
AND
tsri.supplier_id in
<foreach collection="supplierIds" item="item" index="index" open="(" separator="," close=")">
#{item} <-- *此处为错误原因* -->
</foreach>
AND
tsri.reg_id = #{regId}
AND
tsci.status = 0
</update>

  其他的代码不做修改;

    5.结果

    修改后,可正常更新记录,不再报错;