解决:java.sql.SQLException:Value ‘0000-00-00‘ can not be represented as java.sql.Date
问题描述:
数据表中有记录的time字段(属性为timestamp)其值为:“0000-00-00 00:00:00”
程序使用select 语句从中取数据时出现以下异常:
java.sql.SQLException:Value ‘0000-00-00’ can not be represented as java.sql.Date
后查资料发现 “0000-00-00 00:00:00”在mysql中是作为一个特殊值存在的
但 java.sql.Date 将其视为 不合法的值 格式不正确
解决办法:
给jdbc url加上 zeroDateTimeBehavior参数:
datasource.url=jdbc:mysql://localhost:3306/pe?useUnicode=true&characterEncoding=gbk&zeroDateTimeBehavior=convertToNull
zeroDateTimeBehavior=round是为了指定MySql中的DateTime字段默认值查询时的处理方式;默认是抛出异常,
对于值为0000-00-00 00:00:00(默认值)的纪录,如下两种配置,会返回不同的结果:
zeroDateTimeBehavior=round 0001-01-01 00:00:00.0
zeroDateTimeBehavior=convertToNull null
转帖:https://blog.csdn.net/a925907195/article/details/44873565?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522159340169719724839201736%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=159340169719724839201736&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_ecpm_v1~rank_ctr_v4-4-44873565.ecpm_v1_rank_ctr_v4&utm_term=+Value+%011%05trvvv%130000-00-00+00%3A
本文地址:https://blog.csdn.net/qq_43185463/article/details/107150341
推荐阅读
-
解决:java.sql.SQLException:Value ‘0000-00-00‘ can not be represented as java.sql.Date
-
java.sql.SQLException: Value ‘0000-00-00 00:00:00‘ can not be represented as java.sql.Timestamp异常
-
FAQ(60):java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Date
-
java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Tim 异常解决办法
-
mysql错误:Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp;的解决方法
-
FAQ(64):java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Date
-
java.sql.SQLException: Value '0000-00-00' can not be represented as java.sql.Date(已解决)
-
java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp at
-
java.sql.SQLException: Value ‘0000-00-00 00:00:00’ can not be represented as java.sql.Timestamp
-
SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp