Cannot convert value ' 0000-00-00 00:00:00 ' from column 1 to timestamp workaround

Source: Internet
Author: User

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

However, it is not completely secure when using Resultset.gettimestamp (), for example, when a field value of type timestamp in a database is ' 0000-00-00 00:00:00 ', an exception is thrown when reading with this method: cannot Convert value ' 0000-00-00 00:00:00 ' from column 1 to TIMESTAMP, this is because JDBC cannot be ' 0000-00-00 00:00:00 ' Conversion to a java.sql.Timestamp, in Java, want to create a java.util.Date, so its value is ' 0000-00-00 ' is also impossible, 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 translates "&" to &

The following types of characters are escaped in the XML file:

<

<

Less than sign

&gt;

>

Greater than sign

&amp;

&

And

&apos;

Single quotation marks

&quot;

"

Double quotes

Cannot convert value ' 0000-00-00 00:00:00 ' from column 1 to timestamp workaround

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.