Java.sql.SQLException:value; ' 0000-00-00 ' can not is represented as Java.sql.date

Source: Internet
Author: User


Problem Description:

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

post-search data found "0000-00-00 00:00:00" is present in MySQL as a special value.

but java.sql.Date it as an illegal value is not formatted correctly

Workaround:


add The Zerodatetimebehavior parameter to the JDBC URL :


datasource.url=jdbc:mysql://localhost:3306/pe?useunicode=true&characterencoding=gbk& Zerodatetimebehavior=converttonull



Zerodatetimebehavior=round is to specify how the DateTime field in MySql is to be processed when the default value query is queried, and the default is to throw an exception .


For records with a value of 0000-00-00 00:00:00(the default), the following two configurations will return different results:


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


Zerodatetimebehavior=converttonull NULL


This article is from "Doyle" blog, please make sure to keep this source http://conandoyle.blog.51cto.com/11462365/1766953

Java.sql.SQLException:value; ' 0000-00-00 ' can not is 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.