mssql-异常value '0000-00-00' can not be represented as java.sql.Date
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mssql-异常value '0000-00-00' can not be represented as java.sql.Date相关的知识,希望对你有一定的参考价值。
mysql开发中采用ResultSet取值時,不管是才用getString()还是用getDate(),或者getObject,均会拋出如题所述异常.查阅Mysql官方Bug咨询:
是因为日期型(Date或DateTime类型)字串为‘000-00-00‘时,MySQL预设处理方式是拋出异常(exception).只要将jdbc数据库连接字串作如下修改即可:
修改前jdbc连接字符串为:
jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8&characterSetResults=UTF-8
修改後jdbc连接字符串为 :
jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8&characterSetResults=UTF-8&zeroDateTimeBehavior=convertToNull
原文如下:
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. Connector/J 3.1 throws an exception by default when these values are encountered as this is the most correct behavior according to the JDBC and SQL standards. This behavior can be modified using the zeroDateTimeBehavior configuration property. The allowable values are: exception (the default), which throws an SQLException with an SQLState of S1009. convertToNull, which returns NULL instead of the date. round, which rounds the date to the nearest closest value which is 0001-01-01. 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.
以上是关于mssql-异常value '0000-00-00' can not be represented as java.sql.Date的主要内容,如果未能解决你的问题,请参考以下文章
异常:java.sql.SQLException: The server time zone value '?й???????' is unrecognized or represen
java.sql.SQLException: Field 'id' doesn't have a default value异常
关于调试WCF时引发的异常XmlException: Name cannot begin with the '<' character, hexadecimal value 0x
表情存储异常--mybatis抛出异常(java.sql.SQLException: Incorrect string value: 'xF0x9Fx92x94' for co(示例代
在写数据库相关项目时,出现The server time zone value '?й???????' is unrecogni异常。
mysql连接异常:The server time zone value '?й???????' is unrecognized or represents more than one