Bug #12026 | getString on Date-Field in Database creates exception | ||
---|---|---|---|
Submitted: | 19 Jul 2005 8:49 | Modified: | 19 Jul 2005 12:56 |
Reporter: | Florian Rissner | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | Connector / J | Severity: | S2 (Serious) |
Version: | 3.1.10 | OS: | Windows (Windows) |
Assigned to: | CPU Architecture: | Any |
[19 Jul 2005 8:49]
Florian Rissner
[19 Jul 2005 12:56]
Mark Matthews
This is not a bug, and the reasons why (and how to work around it) are documented here in the upgrade notes (always a good idea to check these out when moving to a different major version of the driver): http://dev.mysql.com/doc/connector/j/en/cj-upgrading-3-0-to-3-1.html Quoting: "# 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 a SQLException with a SQLState of 'S1009', 'convertToNull', which returns NULL instead of the date, and '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 get retrieve the unaltered all-zero value as a String. It should be noted that this also precludes using any timezone conversions, therefore the driver will not allow you to enable noDatetimeStringSync and useTimezone at the same time."