本文主要是介绍java.sql.SQLException: Value '0000-00-00 ' can not be represented as java.sql.Timest,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在使用MySql 时, 数据库中的字段类型是timestamp的,默认为0000-00-00, 会发生异常:java.sql.SQLException: Value '0000-00-00 ' can not be represented as java.sql.Timestamp。
原因:“0000-00-00 00:00:00”在mysql中是作为一个特殊值存在的,而 java.sql.Date 将其视为 不合法的值 格式不正确因此产生异常。
解决办法:
jdbc的url加上zeroDateTimeBehavior参数:
如:jdbc.jdbcUrl=jdbc\:mysql\://127.0.0.1\:3306/hysdebugdb?useSSL\=false&zeroDateTimeBehavior=convertToNull
对于值为0000-00-00 00:00:00(默认值)的纪录,如下两种配置,会返回不同的结果:
(1)zeroDateTimeBehavior=round 0001-01-01 00:00:00.0
(2)zeroDateTimeBehavior=convertToNull null
这篇关于java.sql.SQLException: Value '0000-00-00 ' can not be represented as java.sql.Timest的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!