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

今天在使用 Mysql 中的一个 datetime 字段时碰到了一个 Cause: java.sql.SQLException: Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp 异常,之前使用都没有问题,今天突然出现故障。所以我就仔细查看了一下代码,看看最近是否有人改动。通过最终的搜索排查,我把整个过程分享给大家!

根据异常信息,我翻译了一下,大概意思是说,‘0000-00-00 00:00:00’ 这个时间不能用 Java 来表示。虽然数据库中可以存放这个值,但是 Java 中的时间都是从 1970 年开始的。格林威治时间 1970年01月01日00时00分00秒(UTC+8北京时间1970年01月01日08时00分00秒),所以你这个 ‘0000-00-00 00:00:00’ 的时间,Java 表示不了,所以就抛出了这个异常。

完整的异常信息如下:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'audit_time' from result set.  Cause: org.apache.ibatis.executor.result.ResultMapException: Error attempting to get column 'audit_time' from result set.  Cause: java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77)
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446)
    at com.sun.proxy.$Proxy127.selectOne(Unknown Source)
    at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166)
    at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:82)
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59)
    at com.sun.proxy.$Proxy134.findOrderInfo(Unknown Source)

最简单的方法,禁止向数据库插入这种日期。

有其他交流的想法,可以加我创建的Q群:820080257

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值