• Data truncation: Truncated incorrect DOUBLE value 解决方案


      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: 'xACxEDx00x05urx00x17[Ljava.math.BigInteger;x0E|xDBFxE0:`xC6x02x00x00xpx00x00x00x01srx00x14java.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: 'xACxEDx00x05urx00x17[Ljava.math.BigInteger;x0E|xDBFxE0:`xC6x02x00x00xpx00x00x00x01srx00x14java.math.BigIntege'
    ; SQL []; Data truncation: Truncated incorrect DOUBLE value: 'xACxEDx00x05urx00x17[Ljava.math.BigInteger;x0E|xDBFxE0:`xC6x02x00x00xpx00x00x00x01srx00x14java.math.BigIntege'; nested exception is com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: 'xACxEDx00x05urx00x17[Ljava.math.BigInteger;x0E|xDBFxE0:`xC6x02x00x00xpx00x00x00x01srx00x14java.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.结果

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

  • 相关阅读:
    数学函数,字符串函数,聚合函数
    javascript大神修炼记(7)——OOP思想(多态)
    Join的表顺序
    java web 基础
    LVS入门
    Eclipse 一直提示 loading descriptor for 的解决方法
    nginx的配置总结
    nginx入门(安装,启动,关闭,信号量控制)
    如何正大光明的使用 google 进行搜索
    npm报错Error: ENOENT, stat 'D:NodeLearn ode-global'
  • 原文地址:https://www.cnblogs.com/springlight/p/5881759.html
Copyright © 2020-2023  润新知