zoukankan      html  css  js  c++  java
  • Data truncation: Data too long for column 'id' at row 1

    Caused by: org.springframework.dao.DataIntegrityViolationException: Could not execute JDBC batch update; nested exception is org.hibernate.exception.DataException: Could not execute JDBC batch update
        at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:639)
        at org.springframework.orm.hibernate3.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:789)
        at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:663)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:732)
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:701)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:321)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:116)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
        at $Proxy30.getPage(Unknown Source)
        at com.fcms.cms.action.front.FrLalaAct.getAllgame(FrLalaAct.java:65)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at freemarker.ext.beans.BeansWrapper.invokeMethod(BeansWrapper.java:840)
        at freemarker.ext.beans.SimpleMethodModel.exec(SimpleMethodModel.java:106)
        ... 53 more
    Caused by: org.hibernate.exception.DataException: Could not execute JDBC batch update
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:100)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
        at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
        at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
        at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
        at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
        at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
        at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
        at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
        at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:655)
        ... 67 more
    Caused by: java.sql.BatchUpdateException: Data truncation: Data too long for column 'titleimg' at row 1
        at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1269)
        at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:955)
        at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)
        at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
        at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
        ... 75 more
    10437 ERROR [2013-04-15 17:22:49]  

    如题:错误并不是因为字段过长而导致出错的,

            1. 可能是因为数据库里的表设置的字符集不相同。

            2. 也可能真是数据库字段里数据库确实过长(我是遇到的这种情况)。

    例如:在同一个数据库中,存在utf8的表,也存在gbk_chinese_ci的表。

    解决办法:alter table `cms_activity_test` convert to character set gbk collate gbk_chinese_ci;(单独修改指定表的字符集)

    补充:通过在网上查找资料,一般都是修改数据库Mysql的默认字符集修改单个数据库的字符集

    1。 在Mysql数据库目录下找到my.ini文件,然后Ctrl+F查找character-set,修改

    [client]
    
    port=3306
    
    [mysql]
    
    default-character-set=utf8

    2. 修改单个数据库字符集,data目录下找到db.opt文件,然后修改

    default-character-set=gbk
    default-collation=gbk_chinese_ci

    3. 用命令设置

    mysql> SET character_set_client = utf8 ;
    mysql> SET character_set_connection = utf8 ;
    mysql> SET character_set_database = utf8 ;
    mysql> SET character_set_results = utf8 ;
    mysql> SET character_set_server = utf8 ;
    mysql> SET collation_connection = utf8 ;
    mysql> SET collation_database = utf8 ;
    mysql> SET collation_server = utf8 ;

     4. 如果还嫌太麻烦了,就用一个蠢办法,如果整个数据库表不多且数据量不大的情况下,就将整个库导出,然后再去修改文件中字符集不一的表,最后再导入数据库。。。

  • 相关阅读:
    C#进行图片压缩
    C# ASHX生成验证码图片及校验
    SQL和MYSQL及数据库
    复制项目取消SVN
    SQL获取表结构的字段说明和结构
    SQL如何创建存储过程
    python 自带模块 os模块
    osi七层简介(通俗易懂)
    Python sys模块
    python 的装饰器
  • 原文地址:https://www.cnblogs.com/xmaomao/p/3022571.html
Copyright © 2011-2022 走看看