java com.mysql.jdbc.MysqlDataTruncation:数据截断:第 1 行列“名称”的数据太长

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25138039/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 07:25:53  来源:igfitidea点击:

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'name' at row 1

javamysqlnetbeans-platform

提问by user3882220

I am trying to update my database using an update statement, when I am trying to do this it is showing me an error...these are the exceptions I could find here.

我正在尝试使用更新语句更新我的数据库,当我尝试执行此操作时,它向我显示了一个错误...这些是我可以在这里找到的例外情况。

com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'name' at row 1 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2973) at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1600) at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1695) at com.mysql.jdbc.Connection.execSQL(Connection.java:3020) at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1074) at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1008) at data.changing.jButton1ActionPerformed(changing.java:125) at data.changing.access$000(changing.java:21) at data.changing$1.actionPerformed(changing.java:62) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) at java.awt.Component.processMouseEvent(Component.java:6505) at javax.swing.JComponent.processMouseEvent(JComponent.java:3320) at java.awt.Component.processEvent(Component.java:6270) at java.awt.Container.processEvent(Container.java:2229) at java.awt.Component.dispatchEventImpl(Component.java:4861) at java.awt.Container.dispatchEventImpl(Container.java:2287) at java.awt.Component.dispatchEvent(Component.java:4687) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422) at java.awt.Container.dispatchEventImpl(Container.java:2273) at java.awt.Window.dispatchEventImpl(Window.java:2719) at java.awt.Component.dispatchEvent(Component.java:4687) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735) at java.awt.EventQueue.access$200(EventQueue.java:103) at java.awt.EventQueue$3.run(EventQueue.java:694) at java.awt.EventQueue$3.run(EventQueue.java:692) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87) at java.awt.EventQueue$4.run(EventQueue.java:708) at java.awt.EventQueue$4.run(EventQueue.java:706) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:705) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138) at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

com.mysql.jdbc.MysqlDataTruncation:数据截断:com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2973) 的第 1 行 'name' 列的数据太长,位于 com.mysql.jdbc.MysqlIO.sendCommand( MysqlIO.java:1600) 在 com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1695) 在 com.mysql.jdbc.Connection.execSQL(Connection.java:3020) 在 com.mysql.jdbc.Statement.executeUpdate (Statement.java:1074) at com.mysql.jdbc.Statement.executeUpdate(Statement.java:1008) at data.changed.jButton1ActionPerformed(changed.java:125) at data.changed.access$000(changed.java:21) ) 在 javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018) 在 javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341) 在 javax.摇摆。DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402) 在 javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259) 在 javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252) 在 java.awt.Component .processMouseEvent(Component.java:6505) 在 javax.swing.JComponent.processMouseEvent(JComponent.java:3320) 在 java.awt.Component.processEvent(Component.java:6270) 在 java.awt.Container.processEvent(Container. java:2229) 在 java.awt.Component.dispatchEventImpl(Component.java:4861) 在 java.awt.Container.dispatchEventImpl(Container.java:2287) 在 java.awt.Component.dispatchEvent(Component.java:4687) 在java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492) at java.awt。LightweightDispatcher.dispatchEvent(Container.java:4422) at java.awt.Container.dispatchEventImpl(Container.java:2273) at java.awt.Window.dispatchEventImpl(Window.java:2719) at java.awt.Component.dispatchEvent(Component) .java:4687) 在 java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735) 在 java.awt.EventQueue.access$200(EventQueue.java:103) 在 java.awt.EventQueue$3.run(EventQueue.java: 694) 在 java.awt.EventQueue$3.run(EventQueue.java:692) 在 java.security.AccessController.doPrivileged(Native Method) 在 java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) 在 java.security .ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87) 在 java.awt.EventQueue$4.run(EventQueue.java:708) 在 java.awt.EventQueue$4.run(EventQueue.java:706) 在 java.security。AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76) at java.awt.EventQueue.dispatchEvent(EventQueue.java:705) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java) :242) 在 java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161) 在 java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150) 在 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144) .awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138) 在 java.awt.EventDispatchThread.run(EventDispatchThread.java:91)java:705) 在 java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242) 在 java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161) 在 java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread)。 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138) at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)java:705) 在 java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242) 在 java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161) 在 java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread)。 java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138) at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138) 在 java.awt.EventDispatchThread.run(EventDispatchThread.java:91)awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138) 在 java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

回答by user1679378

you can solve this error to adding property in Jboss datasource like jdbc:mysql://localhost:1189/dbName?jdbcCompliantTruncation=false&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8

您可以通过在 Jboss 数据源中添加属性来解决此错误,例如 jdbc:mysql://localhost:1189/dbName?jdbcCompliantTruncation=false&zeroDateTimeBehavior=convertToNull&characterEncoding=UTF-8

you can add jdbc truncation false to solve this error.But your data will be truncated based on value.

您可以添加 jdbc truncation false 来解决此错误。但是您的数据将根据值进行截断。

回答by kirti

This is because size of that coloumn is small then the data you are trying to insert so change the datatype of that coloumn to a larger datatype (for eg in place of char use varchar..) then there will be no problem

这是因为该列的大小很小,然后您尝试插入的数据因此将该列的数据类型更改为更大的数据类型(例如,代替 char 使用 varchar ..)然后就不会有问题

回答by Chris Jaga

You are having this exception probably because you are trying to update a column with a string that is longer than your SQL column length defined in a create statement. Make sure also if you have proper character encoding set in your database, while saving operation with a shorter or equal string (than column definition) may end with such exception if you have special marks in it.

您遇到此异常可能是因为您尝试使用比在 create 语句中定义的 SQL 列长度更长的字符串来更新列。还要确保您的数据库中是否设置了正确的字符编码,同时使用较短或相等的字符串(比列定义)保存操作可能会以此类异常结束,如果其中有特殊标记。