Java.util.Date Turn java.sql.Date lost time problem

Source: Internet
Author: User

java.sql.Date only store date data does not store time data
//Loss of time data
preparedstatement.setdate (1, new Java.sql.Date (Date.gettime ()));
//can handle
preparedstatement.settimestamp (1, New Java.sql.Timestamp (New Java.util.Date () . GetTime ()));
//Want to get complete data, including date and time, so
java.util.Date d = resultset.gettimestamp (1);
//This is a more appropriate process to avoid some potential timestamp problems
java.util.Date d = new Java.util.Date ( Resultset.gettimestamp (1). GetTime ());
this way:
        can receive the Java.util.Date type when storing to the database Then use the GetTime () method to get a long value representing that date object, and then construct a timestamp object with this long value into the database.
       from the storage database, you can get timestamp use his gettime () method to get a long value, The Long value is then used to construct a Java.util.Date object so that the date object can be manipulated. For example, New Simpletimeformat ("Yyyyy-mm-dd HH:mm:ss"). Format () and so on

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.