Bug #19274 | failure to convert datetime '0000-00-00 00:00:00' to TIMESTAMP | ||
---|---|---|---|
Submitted: | 22 Apr 2006 13:23 | Modified: | 22 Apr 2006 22:30 |
Reporter: | Dharmacari Sadara | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | Connector / J | Severity: | S1 (Critical) |
Version: | 3.1.12 and 5.0.0 beta | OS: | Windows (windows XP SP2) |
Assigned to: | CPU Architecture: | Any |
[22 Apr 2006 13:23]
Dharmacari Sadara
[22 Apr 2006 16:18]
Dharmacari Sadara
Connector/J 3.0.17 does not exhibit this behaviour.
[22 Apr 2006 20:36]
Mark Matthews
This is intended behavior. Please see the "upgrading" section of the manual for Connector/J for more details: http://dev.mysql.com/doc/refman/5.0/en/cj-upgrading.html (always a good idea to check this first when upgrading between major versions, either that or read the changelog, or both).
[22 Apr 2006 22:00]
Dharmacari Sadara
which bit was intended? surely not being able to create a record it can't read. please explain!
[22 Apr 2006 22:12]
Dharmacari Sadara
ok. 'zeroDateTimeBehavior' configuration property. just the job.
[22 Apr 2006 22:13]
Mark Matthews
Quoting from the section referenced in the previous comment: "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, 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 time zone conversions, therefore the driver will not allow you to enable noDatetimeStringSync and useTimezone at the same time." Java can _not_ represent an all-zero datetime value (try it, you'll see that you get a date that is nowhere close to zero anything, other than midnight), so we give the user an option as to how they want them handled. Either throw an exception (most correct, since neither JDBC nor standard SQL can deal with all-zero datetimes), convert to NULL or round to the closest date.
[22 Apr 2006 22:30]
Dharmacari Sadara
thanks for your time, mark.
[16 Aug 2006 8:57]
Erki Harand
For new JDBC users (like me) I'd like to point out the exact solution to this problem. You can pass configuration params to Connector/J by DB URL. So to fix this problem use the following URL: jdbc:mysql://localhost:3306/mydbname?zeroDateTimeBehavior=convertToNull