Data truncation: data too long for column Error Analysis

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.