Oracle + hibernate insert time

Source: Internet
Author: User

1. The insert format is.

<Property name = "artAddTime" type = "java. util. Date">

<Column name = "ART_ADD_TIME" length = "7" not-null = "true"/>

</Property>

/**

* Write a time Method

*/

Public staticStringgetStringDate (){

Date d = new Date ();

SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd ");

Return sdf. format (d );

}

Insert:

Art. setArtAddTime (java. SQL. Date. valueOf (new TimeUtil (). getStringDate ()));

Dao. save (art );

="

Art. setArtAddTime (java. SQL. Date. valueOf ("2009-12-12 "));

However, the output value in the Java background is as follows: 00:00:00. 0

2

Insert hours, minutes, And seconds

<Property name = "artAddTime" type = "timestamp"> Date is also supported.

<Column name = "ART_ADD_TIME" not-null = "true"/>

</Property>

Art. setArtAddTime (java. SQL. Timestamp. valueOf (new TimeUtil (). getStringDate ("yyyy-MM-dd HH: mm: ss ")));

Output: 2010-12-1223:49:48. 0 Java output is still one more bit

3. If Oracle is 10 Gb, skip the above steps.

<Property name = "artAddTime" type = "timestamp"> Date is also supported.

<Column name = "ART_ADD_TIME" not-null = "true"/>

</Property>

Art. setArtAddTime (new Date ());

Out: 23:49:48. 0

Related Article

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.