mssql-exception value ' 0000-00-00 ' can not is represented as Java.sql.Date

Source: Internet
Author: User

When using resultset in MySQL development, both getstring () or getdate (), or GetObject, are thrown out title the exception. Check MySQL official Bug Advisory:

It is because the MySQL preset is thrown out of the exception (exception) when the string of the date type (date or datetime type) is ' 000-00-00 '. Simply modify the JDBC database connection string as follows:


The pre-modification JDBC Connection string is:

Jdbc:mysql://localhost:3306/test?characterencoding=utf-8&charactersetresults=utf-8


After modifying the JDBC connection string:

jdbc:mysql://localhost:3306/test?characterencoding=utf-8&charactersetresults=utf-8& Zerodatetimebehavior=converttonull


The original text reads as follows:

DateTimes with All-zero components (0000-00-00 ...)-these values can is not a 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 de Fault when these values was encountered as this was the most correct behavior according to the JDBC and SQL standards. This behavior can is modified using the Zerodatetimebehavior configuration property. The allowable values Are:exception (the default), which throws an SQLException with an SQLState of S1009.converttonull, WH Ich returns NULL instead of the Date.round, which rounds the date to the nearest closest value which is 0001-01-01.startin G with Connector/j 3.1.7, resultset.getstring () can is decoupled from this behavior via Nodatetimestringsync=true (The Def Ault value is false) so, you can retrieve the unaltered All-zero value as a String. It should is noted that this also precludes using any time zone conversions, therefore the driver won't allowYou-enable Nodatetimestringsync and Usetimezone at the same time. 

mssql-exception value ' 0000-00-00 ' can not is represented as Java.sql.Date

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.