zoukankan      html  css  js  c++  java
  • 数据插入报错Incorrect integer value: '' for column

    鄙人不才,在操作数据库存储的时候碰见这样的问题。
    执行sql语句批量插入数据的时候报错

    Incorrect integer value: '' for column 'zhuticengshu' at row 1
    

    我的数据库表设计十分的简单:
    说白了,也就是记录下,以后避免这样的错误发生
    其中id是自增id,其余的字段都是非主键,执行的时候一直报错

    Incorrect integer value: '' for column 'zhuticengshu' at row 1
    

    问题测试

    首先将后台打印出来的SQL复制出来
    通过navicat进行批量的数据插入时,插入数据成功,无异常。

    插入数据

    问题解决

    最后google了一下,发现mysql版本到5以上的都会遇到这样的问题,插入空字符要使用NULL 

     <insert id="insertBatchExt">
        INSERT INTO ${tableName}(
        <foreach collection="keys" item="item" index="index" separator=",">
          ${item.fieldName}
        </foreach>
        )
        VALUES
        <foreach collection="exts" item="ext" index="index" separator=",">
          (
          <foreach collection="ext" item="extitem" index="index" separator=",">
            <choose>
              <when test="extitem.value==null">
                NULL
              </when>
              <otherwise>
                '${extitem.value}'
              </otherwise>
            </choose>
          </foreach>
          )
        </foreach>
      </insert>

     

    网上查资料发现5以上的版本如果是空值应该要写NULL
    这种问题一般mysql 5.x上出现。

    使用Select version();查看,

    我用的是mysql5.0.37,而创建备份的MySQL数据库版本是5.6

    官方解释说:得知新版本mysql对空值插入有"bug",
    要在安装mysql的时候去除默认勾选的enable strict SQL mode
    那么如果我们安装好了mysql怎么办了,解决办法是更改mysql中的配置 my.ini

    my.ini中查找sql-mode,  
    
    默认为sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION",  
    
    将其修改为sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION",重启mysql后即可 

    记录下来与大家共勉,共通学习。

  • 相关阅读:
    利用Fck的javascriptAPI创建fck编辑器
    ExtJs学习笔记(6)_可分页的GridPanel
    SqlTransaction 数据库编程事务使用示例
    ExtJs学习笔记(5)_Ajax示例
    [转贴]三种Ext提交数据的方法
    ExtJs学习笔记(15)_fit布局
    证书创建工具 (Makecert.exe)
    学习ExtJs的几个资源(好多是中文的哦)
    DateTime在ExtJs中无法正确序列化的问题
    ExtJs学习笔记(2)_Basic GridPanel[基本网格]
  • 原文地址:https://www.cnblogs.com/zhaixingzhu/p/12569179.html
Copyright © 2011-2022 走看看