zoukankan      html  css  js  c++  java
  • com.mysql.jdbc.MysqlDataTruncation:Data Truncation:Data too long for column '字段name' at row 1

    1.问题描述:

      在mysql插入数据的时候报错:Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'xxx_name' at row 1

    严重: Servlet.service() for servlet default threw exceptio
    com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'xxx_name' at row 1
     at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2868)
     at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)   
     at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1160)
     at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:685)
     at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1400)
     at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1314)
     at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1299)
     at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:105)
     at org.springframework.jdbc.core.JdbcTemplate$2.doInPreparedStatement(JdbcTemplate.java:745)
     at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:538)
     at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:739)
     at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:797)
     at org.springframework.jdbc.core.JdbcTemplate.update(JdbcTemplate.java:805)
     at com.bester.blog.dao.impl.UserDAOImpl.add(UserDAOImpl.java:25)
     at com.bester.blog.service.impl.UserServiceImpl.add(UserServiceImpl.java:12)
     at com.bester.blog.web.action.UserAction.add(UserAction.java:30)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     at java.lang.reflect.Method.invoke(Method.java:597)

    2.问题分析:

      从字面意思看,是字段长度不够。即使设置为了text还是不够,因为text类型是可变长度的字符串,最多65535个字符,所有,最好是把字段类型设置为longtext,最多存放4294967295个字符

      步骤:进入mysql,use你要改变的数据库,执行语句:alter table testTable modify column xxx_name longtext;

      重启mysql,linux下语句:service mysqld restart

      但是,我的xxx_name字段设置的是varchar(50),而输入的没几个字;

      原因在于:建表的时候,表的编码和字段编码都是默认的latin1,设置为utf8后,问题解决。修改utf-8编码

  • 相关阅读:
    Atom编辑器快捷键大全
    sql随机
    InnoDB表要建议用自增列做主键
    Nginx优化
    Nginx访问限速配置方法详解
    checking for known struct flock definition... configure: error: Don't know how to define struct flock on this system, set --enable-opcache=
    阿里巴巴技术质量新人手册4-研发过程中的测试工作
    阿里巴巴技术质量新人手册3-如何做到测试场景不遗漏
    阿里巴巴技术质量新人手册2-修炼测试基本功
    阿里巴巴技术质量新人手册1-测试开发工程师的角色
  • 原文地址:https://www.cnblogs.com/zs-notes/p/9442605.html
Copyright © 2011-2022 走看看