更新数据库时报错:Data truncation: Incorrect datetime value:

错误如下:

Error updating database.  Cause: com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Incorrect datetime value: '1970-01-01 08:00:00.0' for column 'begin_time' at row 1
### The error may involve com.stylefeng.guns.rest.common.persistence.dao.MoocUserTMapper.updateById-Inline
### The error occurred while setting parameters
### SQL: UPDATE mooc_user_t  SET nick_name=?,  user_sex=?,  birthday=?,  email=?,  user_phone=?,  address=?,    biography=?,  life_state=?,  begin_time=?,  update_time=?  WHERE UUID=?
### Cause: com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Incorrect datetime value: '1970-01-01 08:00:00.0' for column 'begin_time' at row 1
; ]; Data truncation: Incorrect datetime value: '1970-01-01 08:00:00.0' for column 'begin_time' at row 1; nested exception is com.mysql.cj.jdbc.exceptions.MysqlDataTruncation: Data truncation: Incorrect datetime value: '1970-01-01 08:00:00.0' for column 'begin_time' at row 1
	at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:104)
	at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
	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:446)
	at com.sun.proxy.$Proxy93.update(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.update(SqlSessionTemplate.java:294)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:63)

网上搜了很多答案,访问量最多的一种是升级mysql-connection-java-jar的版本,但是我的jar已经是最新版本了,于是找其他办法。花了很长时间,最终终于解决。
        错误原因:数据库中时间类型的原因,导致这样的错误.datetimeYYYY-MM-DD HH:MM:SS格式检索和显示DATETIME值。支持的范围为1000-01-01 00:00:009999-12-31 23:59:59 .而TIMESTAMP值支持的范围1970-01-01 08:00:012038-01-19 11:14:07储存,对于TIMESTAMP来说如果不在这个范围就会报这个错。
        解决方法mysql时间类型由timestamp改成datetime 就行了。

你可能感兴趣的:(错误和异常)