Connected to the MySQL database, when inserting data, the console report:
Com.mysql.jdbc.MysqlDataTruncation:Data Truncation:data too long for column ' user_name ' at row 1
Error, specific information is as follows:
Critical: 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)
........................
Look at this error message, how to have the feeling of déjà vu. But I just can't remember. According to the literal meaning, one is the input out of range. But my user_name field is set to varchar (45), only three Chinese are entered, how can it be exceeded?
Google, a look at the character set word, suddenly think of the past encountered this problem. Just early to the Cloud nine.
The reason: When the table is built, the table encoding and field encoding are the default latin1, set to UTF8, the problem is resolved.
As the saying goes, people can not step into the same river two times, I counted precepts.
(Transferred from: http://my.oschina.net/smile622/blog/106143)