连接的是mysql数据库,插入数据时,控制台报:

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'user_name' at row 1
错误,具体信息如下:

严重: Servlet.service() for servlet default threw exceptio
com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'user_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)
 ........................

看着这错误信息,怎么有似曾相识的感觉呢。但就是记不起来了。根据字面意思,一位是输入超出范围了。但我的user_name字段设置的是varchar(45),只输入了三个中文,怎么可能超出呢?

google一下,一看到字符设置字眼,忽然想起以前碰到过这个问题的。只是早以到了九霄云外罢了。

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

俗话说,人不能两次踏入同一条河流,我算破戒了。

(转自:http://my.oschina.net/smile622/blog/106143)

com.mysql.jdbc.MysqlDataTruncation: Data trunca...的更多相关文章

  1. mysql 插入中文报错: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value...

    总结写在前面, 总结: 当Java通过jdbc链接mysql插入中文时,要保证程序可以正常执行,而且插入的中文不会乱码, mysql服务器端,对数据表(不是数据库)的编码设置,要保证是支持中文的,例如 ...

  2. Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: 'L

    1.错误叙述性说明 [ERROR:]2015-06-08 09:49:42,523 [异常拦截] org.hibernate.exception.DataException: error execut ...

  3. Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: 'L

    1.错误描述 [ERROR:]2015-06-08 09:49:42,523 [异常拦截] org.hibernate.exception.DataException: error executing ...

  4. Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'content' a

    1.错误描述 org.hibernate.exception.DataException: could not execute statement at org.hibernate.exception ...

  5. Error updating database. Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: 'as3'

    执行更新时的出错信息 Whitelabel Error Page This application has no explicit mapping for /error, so you are see ...

  6. Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'img' at row 1故障

    Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'img' at ro ...

  7. 数据库报错com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'ua' at row 1

    记一次报错记录,成长路上的点滴 明明使用浏览器或者微信开发工具调试接口没有问题,但是在真机测试时候就出问题了.(((¬_¬)) 500服务器内部错误,要死的节奏啊 登陆tomcat服务器 使用命令ta ...

  8. com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value:...

    在使用mybatis的@Update注解的时候,报了一个这样的错 ### Error updating database. Cause: com.mysql.jdbc.MysqlDataTruncat ...

  9. 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 fo ...

随机推荐

  1. dbcp2连接池获取数据库连接Connection

    一.先来看看手工创建的方式 public static Connection getConnection() { Connection conn = null; try { Class.forName ...

  2. ocr 识别 github 源码

    参考 [1] https://github.com/eragonruan/text-detection-ctpn [2] https://github.com/senlinuc/caffe_ocr [ ...

  3. spring in action小结3 运行时值注入

    讨论依赖注入的时候,通常讨论的是一个bean引用注入到另一个bean的属性或者构造器参数中.bean装配的另一个方面是将值注入到bean的属性或者构造器参数中.避免硬编码的方式就是运行时确定值. sp ...

  4. php调试函数

    void debug_print_backtrace ([ int $options = 0 [, int $limit = 0 ]] ) array debug_backtrace ([ int $ ...

  5. sphider 丁廷臣简体中文完美汉化版带蜘蛛搜索引擎程序 v1.3.4

    sphider 丁廷臣简体中文完美汉化版带蜘蛛搜索引擎程序 v1.3.4是最官方的新版,免费开源,用官方最新发布原版汉化.未更改任何内核文件. Sphider 是一个完美的带有蜘蛛的搜索引擎程序. S ...

  6. How to Install Xcode, Homebrew, Git, RVM, Ruby & Rails on Snow Leopard, Lion, Mountain Lion, and Mavericks

    After following many outdated and incomplete instructions for setting up a web development environme ...

  7. 【转】用python实现简单的文本情感分析

    import jieba import numpy as np # 打开词典文件,返回列表 def open_dict(Dict='hahah',path = r'/Users/zhangzhengh ...

  8. Juqery 定时器 settimeout setInterval

    setTimeout 只执行一次 setTimeout(loading_tree,2000); function loading_tree(){ $('body').mLoading("hi ...

  9. MySQL 使用 SSL 连接(附 Docker 例子)

    查看是否支持 SSL 首先在 MySQL 上执行如下命令, 查询是否 MySQL 支持 SSL: mysql> SHOW VARIABLES LIKE 'have_ssl'; +-------- ...

  10. 基于HTML5 Canvas生成粒子效果的人物头像

    前面我们分享过一个HTML5 Canvas实现的图像马赛克模糊效果,HTML5处理图片真的非常简单.今天我们要再利用HTML5 Canvas实现一个粒子效果的人物头像,你可以任意选择一张头像图片,接下 ...