Cannot convert value ' 0000-00-00 00:00:00 ' from column 1 to TIMESTAMP.

Source: Internet
Author: User

When you recently imported data from MySQL, you found that some records could not be imported. The reason is that the 0000-00-00 00:00:00 time format could not be converted, the online search, in this way can solve the problem.

Using the datetime type in the MySQL database to store the time, you should use Resultset.gettimestamp () When reading this field in JDBC, which will get a java.sql.Timestamp type of data. Neither resultset.getdate () nor resultset.gettime () can be used here because the former does not include time data and the latter does not include date data.

However, it is not completely secure when using Resultset.gettimestamp (), for example, when a timestamp type in a database has a field value of ' 0000-00-00 00:00:00 ', an exception is thrown when the method is used for reading: cannot Convert value ' 0000-00-00 00:00:00 ' from column 1 to TIMESTAMP because JDBC cannot convert ' 0000-00-00 00:00:00 ' to a java.sql. Timestamp, in Java, it is impossible to create a java.util.Date value of ' 0000-00-00 ', the oldest date should be ' 0001-01-01 00:00:00 '.

Solution 1.String url = "jdbc:mysql://localhost:3306/test?relaxautocommit=true&zerodatetimebehavior= Converttonull";

Note that if the symbol "&" is unsuccessful, it needs to be converted to a specific character, as shown in the following table, which converts "&" to &

There are several types of characters in the XML file that you want to escape from:

<

<

Less than sign

&gt;

>

Greater-than sign

&amp;

&

And

&apos;

'

Single quotation mark

&quot;

"

Double quotes

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.