About the setdate of PreparedStatement

Source: Internet
Author: User

Write code today when you need to insert a date type into the database time, use to preparedstatement the time to find Setdate () method always give me prompt error, the results of a check, found PreparedStatement setdate () The time type of the second parameter of the method is java.sql.Date, so it is wrong when I use java.util.Date to set it.

What should be the conversion between Java.sql.Date and java.util.Date? After checking the data can be converted:

Java.util.Date utildate = new Java.util.Date ();

Java.sql.Date sqldate = new Java.sql.Date (Utildate.gettime ());

The converted Sqldate can be set into the PreparedStatement inside. And then you think about how the time format is set up? After experimentation, it is concluded that the format of the time is xxxx-xx-xx, as shown in

  

About the setdate of PreparedStatement

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.