How to convert java. util. date to Java. SQL. Date?

Source: Internet
Author: User
How to convert java. util. date to Java. SQL. Date?
Conversion:

Java. SQL. Date SD;
Java. util. Date UD;
// Initialize the UD such as UD = new java. util. Date ();

SD = new java. SQL. Date (ud. gettime ());

If you want to insert data to the database and the corresponding field is of the date type
You can use the preparedstatement. setdate (INT, java. SQL. Date) method.
The Java. SQL. date can be obtained using the above method.

You can also use the database to provide the to_date function.
For example, the existing ud
To_date (New simpledateformat (). Format (UD, "yyyy-mm-dd hh: mm: SS "),
"YYYY-MM-DD hh24: MI: SS ")
Note that the representation format in Java is different from the format provided by the database.

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.