com.mysql.jdbc.MysqlDataTruncation: Data trunca...

连接的是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后,问题解决。

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

转载于:https://my.oschina.net/smile622/blog/106143

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值