Time loss caused by oracle9 or 11 using oracle10 drivers

Source: Internet
Author: User

In Oracle DDL, column-type date includes time + time and is accurate to milliseconds. the column type does not exist only for date (excluding time), while the column type Timestamp can be considered as a date type with higher accuracy, accurate to 1000 s (only s in Windows ).

There are two types of date in Java: one is Java with time. util. date, a type of Java with only a date without time. SQL. date. there is also a Java with both time and date. SQL. timestamp.

1. Write oracle in Java

1. When Java writes data to the Oracle date column:

Java. util. Date, java. SQL. timestamp.

Java. SQL. Date, Oracle only writes logs, and the time part is stored at 00:00:00 by default.

2. When Java is written to the timestamp column of Oracle:

Java. SQL. timestamp should be used

Ii. Oracle reads Java

1. if a column of the date type is used (it is troublesome. If the existing driver ojdbc14 is used, Java is used to convert the date type to the date class of Java. util. date inheritance class Java. SQL. date, not Java. util. date, because the former does not retain the time part, only the date. the time part of the query is lost .)

If an incorrect driver is used in Java, there are three solutions:

1) solution: (1 ). change the date type to the timestamp type (not recommended ). (2 ). set oracle in the connection parameters of datasource. JDBC. v8compatible = true; (compatible with the old driver. Because the old driver is correctly converted, the date column is correctly converted to Java. util. date

2) convert the date column type to the timestamp type. All Drivers of Oracle will convert the timestamp to Java. SQL. timestamp. The time part will not be lost.

References:

Http://www.blogjava.net/midea0978/archive/2008/06/13/207655.html

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.