MySQL JDBC throws an exception once.
Data truncation: data too long for Column
After thinking, there may be two possible causes:
I. Insufficient field length.
You can select a longer field, for example:
Varchar-> text-> mediumtext-> longtext-> longblob
In addition, MySQL does not seem to have the nvarchar type.
Ii. Character Set options in the data source URL are inconsistent with the actual character set in the database table
If it is unified, the Java code should be written as follows:
String drivername = "com. MySQL. JDBC. Driver ";
String dburl = "JDBC: mysql: // localhost: 3306/cmsproj? Useunicode = true & characterencoding = UTF-8 ";
The data table creation method is
Create Table XXX
(...
) Engine = MyISAM default charset = utf8
Note:
* The database can also specify character sets. However, if the default character set is used in create table, create table takes precedence.
* The use of utf8 or GBK in Java code compilation does not affect the system, as long as the input parameters are not garbled.
In fact, it can also work if the character set is not uniform, but there is a certain probability that a data truncation exception will be thrown. For example, the utf8 character set is specified in the URL, but the utf8 character set is not specified in the Table creation or the default Latin character set is used, an exception may be thrown.
This article from the "weimingtom heart-to-heart" blog, please be sure to keep this source http://weimingtom.blog.51cto.com/5787478/1551786
Data truncation: data too long for column Error Analysis