java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp

详细错误信息:

org.springframework.dao.TransientDataAccessResourceException: 
### Error querying database. Cause: java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
### The error may exist in URL [jar:file:/D:/apache-tomcat-8.0.22/webapps/xinghe-platform-web/WEB-INF/lib/xinghe-interaction-0.0.1-SNAPSHOT.jar!/com/xinghe/edu/inter/model/mapper/LessonMapper.xml]
### The error may involve defaultParameterMap
### The error occurred while setting parameters
### SQL: SELECT ID, LESSON_HISTORY_LOCAL_ID, USER_LOCAL_ID, USER_NAME, STARTTIME, ENDTIME, CLASSROOM_NUM, STAND_UP_TIMES, LOCAL_ID, PRAISE_NUM, BAD_NUM, STAR_LEVEL , (select TRUE_NAME from auth_user b1 where b1.ID = b.USER_LOCAL_ID) TEACHER_NAME FROM lesson b
### Cause: java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
; SQL []; Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp; nested exception is java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
    at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:108)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371)
    at com.sun.proxy.$Proxy17.selectList(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.selectList(SqlSessionTemplate.java:198)
    at com.xinghe.frame.base.BaseMyIbatisDao.findByMap(BaseMyIbatisDao.java:335)
    at com.xinghe.frame.base.BaseManager.find(BaseManager.java:147)
    at com.xinghe.frame.base.BaseManager.findBy(BaseManager.java:143)
    at com.xinghe.frame.base.BaseManager$$FastClassBySpringCGLIB$$4fc83aac.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
    at com.auth.aop.interceptor.DbAnnotationMethodInterceptor.invoke(DbAnnotationMethodInterceptor.java:61)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653)
    at com.xinghe.edu.interaction.service.EachLessonManager$$EnhancerBySpringCGLIB$$a2e8c27e.findBy(<generated>)
    at com.xinghe.platform.task.ClassroomResourcesRelatedTask.relatedResources(ClassroomResourcesRelatedTask.java:67)
    at com.xinghe.platform.task.ClassroomResourcesRelatedTask.related(ClassroomResourcesRelatedTask.java:58)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
    at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1078)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:975)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:920)
    at com.mysql.jdbc.ResultSetRow.getTimestampFast(ResultSetRow.java:1102)
    at com.mysql.jdbc.ByteArrayRow.getTimestampFast(ByteArrayRow.java:127)
    at com.mysql.jdbc.ResultSetImpl.getTimestampInternal(ResultSetImpl.java:6592)
    at com.mysql.jdbc.ResultSetImpl.getTimestamp(ResultSetImpl.java:6192)
    at com.mysql.jdbc.ResultSetImpl.getTimestamp(ResultSetImpl.java:6230)
    at com.mchange.v2.c3p0.impl.NewProxyResultSet.getTimestamp(NewProxyResultSet.java:3394)
    at org.apache.ibatis.type.SqlTimestampTypeHandler.getNullableResult(SqlTimestampTypeHandler.java:38)
    at org.apache.ibatis.type.SqlTimestampTypeHandler.getNullableResult(SqlTimestampTypeHandler.java:27)
    at org.apache.ibatis.type.BaseTypeHandler.getResult(BaseTypeHandler.java:55)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getPropertyMappingValue(DefaultResultSetHandler.java:390)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.applyPropertyMappings(DefaultResultSetHandler.java:364)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getRowValue(DefaultResultSetHandler.java:338)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValuesForSimpleResultMap(DefaultResultSetHandler.java:291)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleRowValues(DefaultResultSetHandler.java:266)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSet(DefaultResultSetHandler.java:236)
    at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.handleResultSets(DefaultResultSetHandler.java:150)
    at org.apache.ibatis.executor.statement.PreparedStatementHandler.query(PreparedStatementHandler.java:60)
    at org.apache.ibatis.executor.statement.RoutingStatementHandler.query(RoutingStatementHandler.java:73)
    at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:60)
    at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:267)
    at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:137)
    at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:120)
    at sun.reflect.GeneratedMethodAccessor67.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49)
    at com.xinghe.frame.mybatis.FlushCacheInterceptor.intercept(FlushCacheInterceptor.java:61)
    at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:60)
    at com.sun.proxy.$Proxy24.query(Unknown Source)
    at sun.reflect.GeneratedMethodAccessor67.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.ibatis.plugin.Invocation.proceed(Invocation.java:49)
    at com.xinghe.frame.mybatis.OffsetLimitInterceptor.intercept(OffsetLimitInterceptor.java:55)
    at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:60)
    at com.sun.proxy.$Proxy24.query(Unknown Source)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:108)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:102)
    at sun.reflect.GeneratedMethodAccessor71.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
    ... 29 more

在使用MySql 时, 数据库中的字段类型是timestamp的,默认为0000-00-00, 会发生异常:java.sql.SQLException: Value ‘0000-00-00 ’ can not be represented as java.sql.Timestamp

解决办法:

给jdbc url加上 zeroDateTimeBehavior参数:

datasource.url=jdbc:mysql://localhost:3306/testdb?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true

zeroDateTimeBehavior=round是为了指定MySql中的DateTime字段默认值查询时的处理方式;默认是抛出异常,

对于值为0000-00-00 00:00:00(默认值)的纪录,如下两种配置,会返回不同的结果:

zeroDateTimeBehavior=round 0001-01-01 00:00:00.0

zeroDateTimeBehavior=convertToNull null

你可能感兴趣的:(java,spring,mybatis,Timestamp,SQLExcepti)