在程序中写了一段代码向数据库中插入数据,出现了data too long for column 'name' at row 1的问题。在google搜了一下解决方法,真是五花八门,也逐一试了一遍,终于终于将问题解决了。
下面先贴一下网上的众多解决
1、修改my.ini文件:
将sql-mode=STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION注释掉,ok!
2、修改数据库编码为utf8,jsp,servlet编码转换为utf8存入
3、只知道是中文处理的问题,但不知道如何改.最好的方法是把字段定得长一些
4、把mysql的字符集设为utf8(通过修改my.ini,把所有的latin1改为utf8)并且通过show variables like '%char%';
5、以前我也遇到过类似的情况,我的建议:在装数据库的时候把你的字符集设置为gb2312,然后你建表的时候,汉字默认都是gb2312在连接数据库的时候不要写成 characterEnconding=true&charset=gb2312,把这个去掉。然后在连接的时候写c最好用gbk,gb2312 对某些不常见的字符会出现Data too long for column,比如“珺”字等,至于数据库,只有默认的字符集是gb2312或者gbk或者utf8都没什么问题
对于我这里的情况也简要描述下,我的mysql把server端,client端,connection的字符设置都为gbk,在控制太插入中文字没有问题,但是从程序里面插入中文字就存在问题了。
用第一种方法试了下,不行。
用将所有的编码格式改为utf8,以前数据库里面的中文字全变成了乱码,第二种方法也不行
第3种方法,我将数据库里面的name设为varchar(255)这是足够大的,可以存125个汉字了,还是不行,即使是存一个汉字也会报Data too long for column的错误,因此第3种方法显然是瞎掰。
用第四种方法试了下,也这是提供你信息,你的数据库各个端都采用什么编码方式,并不能解决问题
最后试了第五种方法,没有完全按照它所说的做,在插入数据库之前先执行stat.execute("set names gb2312");就能成功将中文字插入到数据库中。
这是为什么了?在采用第四种方式时,得到这样的信息 +--------------------------+---------------------------------------------------- -----+ | Variable_name | Value | +--------------------------+---------------------------------------------------- -----+ | character_set_client | gbk | | character_set_connection | gbk | | character_set_database | gbk | | character_set_results | gbk | | character_set_server | gbk | | character_set_system | utf8 | | character_sets_dir | C:\Program Files\MySQL\MySQL Server 5.0\share\chars ets\ | +--------------------------+---------------------------------------------------- 说明我的系统编码方式与数据库的编码方式不符,用stat.execute("set names gb2312");将编码方式先改为gb2312方式,就可以解决这样的问题。
分享到:
相关推荐
解决办法: 在my.ini里找到 sql-mode=”STRICT_TRANS_TABLES,NO_AUTO_Create_USER,NO_ENGINE_SUBSTITUTION” 把其中的STRICT_TRANS_TABLES,去掉, 或者把sql-mode=STRICT_TRANS_TABLES,NO_AUTO_Create_USER,NO_ENGINE_...
Each index row in node pages contains an index key (or set of keys for a composite index) and a ...at the next level for which the first key value is the same as the key value in the current index row....
Application (10) Data 1: Application resource name The rsc_bin column of master..syslockinfo contains the resource block in hexadecimal format. For an example of how to decode value from this column ...
Q440760 - Export to PDF - The File Save dialog is not shown if the default file name for a report is too long B218629 - In the Page Number Format dialog, the "Start At" field value is incorrectly ...
Q440760 - Export to PDF - The File Save dialog is not shown if the default file name for a report is too long B218629 - In the Page Number Format dialog, the "Start At" field value is incorrectly ...
Q440760 - Export to PDF - The File Save dialog is not shown if the default file name for a report is too long B218629 - In the Page Number Format dialog, the "Start At" field value is incorrectly ...
Q440760 - Export to PDF - The File Save dialog is not shown if the default file name for a report is too long B218629 - In the Page Number Format dialog, the "Start At" field value is incorrectly ...
Q440760 - Export to PDF - The File Save dialog is not shown if the default file name for a report is too long B218629 - In the Page Number Format dialog, the "Start At" field value is incorrectly ...
Q440760 - Export to PDF - The File Save dialog is not shown if the default file name for a report is too long B218629 - In the Page Number Format dialog, the "Start At" field value is incorrectly ...
Q440760 - Export to PDF - The File Save dialog is not shown if the default file name for a report is too long B218629 - In the Page Number Format dialog, the "Start At" field value is incorrectly ...
- improved split mechanism (added TfrxStretcheable.HasNextDataPart for complicated data like RTF tables) - improved crosstab speed when using repeat band with crosstab object version 4.9 ------------...
as you can delete unwanted large attachments that take too much disk space in your mailbox. You can also save the list of attachments into xml/html/text/csv file. System Requirements ==============...
二进制数据类型 row 1~2000字节 可变长二进制数据,在具体定义字段的时候必须指明最大长度n long raw 1~2GB 可变长二进制数据 LOB数据类型 clob 1~4GB 只能存储字符数据 nclob 1~4GB 保存本地语言字符集数据 blob...
ent_upd1.exe file appropriate for your locale.* To install this update from the Web, double-click the self-executing installation file and follow the prompts. * The Delphi 7 documentation PDF files ...
1.简介 PHP是能让你生成动态网页的工具之一。PHP网页文件被当作一般HTML网页文件来处理并且在编辑时你可以用编辑HTML的常规方法编写PHP。 PHP代表:超文本预处理器(PHP: Hypertext Preprocessor)。PHP是完全免费...