Value ' 0000-00-00 ' can not represented as Java.sql.Date

Source: Internet
Author: User

Value ' 0000-00-00 ' can not represented as Java.sql.Datetime 2014-07-30 09:00:50 iteye-Blog Originalhttp://josh-persistence.iteye.com/blog/2098415 ThemesJava SQL

Java.sql.SQLException:Value ' 0000-00-00 00:00:00 ' can not is represented as Java.sql.Timestamp

problem description, in a Java application, the data table has a record time field (property of timestamp) whose value is: "0000-00-00 00:00:00"

The following exception occurs when a program uses the SELECT statement to fetch data from:

Java.sql.SQLException:Value ' 0000-00-00 ' can not is represented as Java.sql.Date

This is because "0000-00-00 00:00:00" exists as a special value in MySQL, but in Java, Java.sql.Date is considered an illegal value and is considered malformed by the JVM.

Workaround:

Add the Zerodatetimebehavior parameter to the JDBC URL:

DATASOURCE.URL=JDBC:MYSQL://LOCALHOST:3306/PE?USEUNICODE=TRUE&CHARACTERENCODING=GBK & Zerodatetimebehavior=converttonull

For records with a value of 0000-00-00 00:00:00 (the default), different results are returned depending on the configuration:

Not configured: Default return exception

Zerodatetimebehavior=round 0001-01-01 00:00:00.0

Zerodatetimebehavior=converttonull NULL

But it is possible to report a new exception:

The reference to entity "characterencoding" must end with the '; ' delimiter

This may be due to forgetting to translate special symbols in the properties file or in an XML file.

Jdbc:mysql://192.168.1.155:3306/diandi?useunicode=true&characterencoding=utf-8 & Zerodatetimebehavior=converttonull

Need to read:

Jdbc:mysql://192.168.1.155:3306/diandi?useunicode=true&characterencoding=utf-8 & Zerodatetimebehavior=converttonull

There are several types of characters to be escaped and replaced:

<

<

Less than sign

&gt;

>

Greater than sign

&amp;

&

And

&apos;

Single quotation marks

&quot;

"

Double quotes

Value ' 0000-00-00 ' can not represented as java.sql.Date

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.