Oracle Date Field Operations

Source: Internet
Author: User

Oracle Date Field Operations in java oracle operations, Date field is a headache, in fact, a careful study is not difficult to grasp. For example, the table book contains two fields: name varchar2 (20) // book name and buydate Date // purchase Date. You have created a database Connection conn; www.2cto.com method 1. Use java. SQL. Date to implement a simple Date in yyyy-mm-dd format. Java. SQL. Date does not support the time format. Do not use new java. SQL. Date (int year, int month, int date), because the time difference problem must be processed. PreparedStatement pstmt = conn. prepareStatement ("insert into book (name, buydate) values (?,?) "); Java. SQL. date buydate = java. SQL. date. valueOf ("2005-06-08"); pstmt. setString (1, "Java programming ideas"); pstmt. setDate (2, buydate when using pstmt.exe cute (); Method 2: Use java. SQL. timestamp. Do not use new Timestamp (....) preparedStatement pstmt = conn. prepareStatement ("insert into book (name, buydate) values (?,?) "); Java. SQL. timestamp buydate = java. SQL. timestamp. valueOf ("2004-06-08 05: 33: 99"); pstmt. setString (1, "Java programming ideas"); pstmt. setTimestamp (2, buydate when using pstmt.exe cute (); Method 3: Use the oracle to_date built-in function PreparedStatement pstmt = conn. prepareStatement ("insert into book (name, buydate) values (?, To_date (?, 'Yyyy-mm-dd hh24: mi: ss') "); String buydate =" 2004-06-08 05: 33: 99 "; pstmt. setString (1, "Java programming ideas"); pstmt. setString (2, buydate when using pstmt.exe cute (); www.2cto.com attached: oracle Date Format parameter description d: day of the week: the name of the day, with spaces filled with 9 Characters dd: the day of the month ddd: The day of the year dy: the abbreviation of the day iw: the week of the year in the ISO standard iyyy: the four-digit year of the ISO standard yyyy: four-digit year yyy, yy, y: the last three digits of the year, two digits, one digit hh: hour, 12 hours hh24: hour, 24 hours mi: minute ss: second mm: month mon: month abbreviated month: full name of the month w: the nth week of the month ww: the nth week of the year

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.