解决data too long for column 'name' at row 1


我遇到这个问题,在使用第3种方法,解决了问题,因为是我的数据库的字段的长度不够,别的方法没有试过




最先试一试最简单的测试方式就是先修改my.ini文件中的-default-character-set = gb2312或utf8,重启mysql再输入数据,如果不行,再考虑以下办法。

 

在程序中写了一段代码向数据库中插入数据,出现了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方式,就可以解决这样的问题。 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
=============================== ==注意:一共2个压缩包,这是第1个== =============================== DevExpress VCL v2012 vol 1.6 包含所有源码、例子、帮助 如果你安装过其它版本的DevExpressVCL,安装前请完全卸载老版本的Dev控件,并执行“清理Dev残余文件”,清理System32下的DevExpress的BPL文件。 What's New in DevExpress VCL 12.1.6 Release Notes The following sections list all minor and major changes in DevExpress VCL 12.1.6. Note that products, controls and libraries which aren't mentioned in the list below are included in the unified installer for compatibility, but have not been updated. New Features/Changes ExpressLayout Control S170028 - Documentation - Describe runtime object access capabilities in the "On-Form Object Access" topic S170040 - Documentation - Update the "ExpressLayout Control: Resource Strings" topic with resource strings used in customization context menus ExpressTile Control S170009 - Add the capability to determine if a specific point corresponds to a tile control's title using HitTest information Resolved Issues VCL Subscription Q434991 - Data-aware container controls - Format settings are not applied to cells ExpressBars Suite Q440463 - Ribbon - TdxBarApplicationMenu - Check marks displayed for TdxBarLargeButton items appear highly pixelated Q441061 - Ribbon - TdxRibbonBackstageView opened in a new Ribbon Form created in an application remains visible on screen if this Ribbon Form is closed via its Close button Q425185 - Ribbon Form - Incorrect text color is applied to a maximized form's caption B219006 - TcxBarEditItem - LookupComboBox - An error occurs when moving focus from one lookup bar item to another ExpressDocking Library Q440931 - TdxDockPanel is not activated by clicking the panel's tab in TdxTabContainerDockSite ExpressLayout Control Q434679 - A layout group fires the OnTabChanging event twice if the event's handler calls Application.ProcessMessages Q433283 - A layout group with a label layout item that is set to occupy the entire client area of its group has an incorrect width B218895 - Documentation - Incorrect topic navigation due to a corrupt HLP file (Delphi 7 only) ExpressPrinting System 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 validated for character-based number formats B218627 - TBasedxReportLink descendants - Customized values of the TimeFormat, DateFormat and PageFormat properties are reset to their default values in some cases if default formats have been customized at the TdxComponentPrinter level Q440453 - TdxComponentPrinter - The Date And Time dialog cannot be re-opened after the last time format has been selected in the Available Time Formats list Q435027 - The Print Preview window freezes when invoked from a window located in a DLL file B219022 - TreeList Report Link - Rich text formatting is missing when printing cxRichEdit columns ExpressQuantumGrid Suite Q404033 - An exception is thrown when the selection is modified within the View's OnSelectionChanged event handler Q430561 - Assigning a Table View column to a Layout View data item or Card View row modifies the assignee's GroupIndex property Q434910 - Compilation errors occur after the View's Navigator.InfoPanel.OnClick event handler has been created at design time due to the missing cxNavigator unit in the 'uses' clause Q437880 - Data-aware Views - The "RecordIndex out of range" exception is thrown when removing a record if the View contains unbound columns Q433982 - Data-aware Views - The "RowIndex out of range" exception is thrown when updating the TClientDataSet bound to the View within a form's OnDestroy event handler using EmptyDataSet, etc. B218884 - Layout View - Card captions and currently focused items are incorrectly painted in selected cards B218883 - Layout View - Cell content areas are hot-tracked regardless of the View's OptionsBehavior.ItemHotTrack property value B218885 - Layout View - The text color specified in the View's Styles.OnGetItemStyle event handler is not applied to card layout items Q438267 - Server Mode - Clicking a Filter Row cell in a column containing Null values throws the "Could not convert variant of type (Null) into type (OleStr)" exception Q435475 - Tabular and Layout Views - The View does not synchronize edit value changes with the data controller in the OnEditChanged event handler if DataController.Options includes dcoImmediatePost, and a grid item's Properties.ImmediatePost property is set to True ExpressQuantumTreeList Suite Q434260 - TcxDBTreeList refreshes all data if a bound dataset was edited via the TreeList control when the OptionsData.SmartRefresh property is set to True Q435693 - TcxTreeList - An AV occurs when adding nodes in RAD Studio XE3 at design time ExpressScheduler Suite Q431232 - cxDateNavigator - The date navigator does not maintain the number of selected weeks always visible on screen when scrolling months backwards Q433746 - Day View - Resizing an event that lasts more than one day past 11:59pm increases the event's duration by one day if the ShowAllDayEventsInContentArea property is set to True ExpressSkins Library Q435604 - TdxBevel - Additional colors are not defined for the control in the Blueprint, DevExpressStyle, Seven, SevenClassic, VS2010, and Whiteprint skins Q436337 - The Skin Editor does not generate skin packages for RAD Studio XE3 ExpressSpreadSheet B218380 - The TcxSSViewInfoData record fields in the cxSSViewInfo.hpp file generated by a C++Builder application have an invalid alignment ExpressTile Control Q432087 - cxDateEdit controls are not displayed on a detail page when activating this page for the second and subsequent times in Windows XP B218389 - Focus does not move to the previous/next row when it passes the first/last tile within the current row if a tile control's OptionsBehavior.FocusItemOnCycle property is set to True ExpressVerticalGrid Suite Q439250 - Closing the Customization form does not disable the customization mode in error Common Libraries ExpressEditors Library Q431767 - TdxDBBreadcrumbEdit does not update its content after a new record is inserted into a database table in XE2 Update 4 Q434043 - Background and text colors are not applied to a read-only editor if its Properties.ReadOnly property is set via RepositoryItem Q434045 - cxMemo - Scrollbars are not shown if the editor is the last object in a DFM file, the editor has no text, and its Properties.ScrollBars property is set to ssBoth at design time B218869 - dxBreadCrumbEdit - A node's DeleteChildren method does not update the node's HasChildren property Q437728 - dxBreadcrumbEdit - An AV occurs when clicking the Root in a node's drop-down window when the selected node's children are repopulated within an OnPathSelect event handler B213307 - ExpressEditors are erroneously painted by VCL styles, as if they are standard VCL editors Q436036 - Some editors discard changes to the edit value if these changes were made by pasting data from the clipboard, using the Backspace key, etc. Q433948 - TcxImage - Intersections with other transparent DevExpress editors may appear distorted Q440954 - TcxScrollBox - The Create method does not use the GetViewInfoClass method Q436691 - TcxShellBrowserDialog - Memory leaks when selecting a file or folder in the dialog and clicking the OK button Q432788 - TcxSplitter - In Delphi 2010 and later, changes to the AlignSplitter property erroneously cause form resizing Q434498 - TdxShellBreadcrumbEdit - An AV occurs when selecting a file in a linked shell tree view B218303 - TdxShellBreadcrumbEdit - Files selected in a linked shell tree view are added as nodes (folders) to the breadcrumb editor ExpressLibrary Q432285 - TdxScreenTip - An AV occurs when displaying hints for ExpressQuantumGrid cells after ScreenTips have been shown by hint controllers located on other forms

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值