|
在Mysql数据库中使用DATETIME类型来存储时间,使用JDBC中读取这个字段的时候,应该使用 ResultSet.getTimestamp(),这样会得到一个java.sql.Timestamp类型的数据。在这里既不能使用 ResultSet.getDate(),也不能使用ResultSet.getTime(),因为前者不包括time数据,后者不包括date数据。 Datetimes with all-zero components (0000-00-00 ...) — These values can not be represented reliably in Java. Connector/J 3.0.x always converted them to NULL when being read from a ResultSet.
Starting with Connector/J 3.1.7, ResultSet.getString() can be decoupled from this behavior via noDatetimeStringSync=true (the default value is false) so that you can retrieve the unaltered all-zero value as a String. It should be noted that this also precludes using any time zone conversions, therefore the driver will not allow you to enable noDatetimeStringSync and useTimezone at the same time. 所以,在JDBC URL中加入zeroDateTimeBehavior信息,既可以解决: 当然,也可以使用另外一个策略:round |
zeroDateTimeBehavior=convertToNull
最新推荐文章于 2022-10-16 12:15:46 发布
本文介绍如何解决在MySQL中读取特殊零日期('0000-00-00')时出现的JDBC异常问题,并提供了解决方案,如通过配置zeroDateTimeBehavior属性为convertToNull或round。
Cannot convert value '0000-00-00 00:00:00' from column 1 to TIMESTAMP
2008年09月22日 星期一 11:13
3468

被折叠的 条评论
为什么被折叠?



