There is no time, minute, and second for the Date type Field Obtained by oracle10g. solution!

Source: Internet
Author: User

In a general database, the DATE field only indicates the DATE, excluding the DATE information. In an Oracle database, the DATE data type includes the DATE and time. For different Oracle jdbc driver versions, there are some differences in the handling of this problem.

Recently, ORACLE 10 Gb is used. The time field is set to the DATE type as required. It is found that hibernate uses native SQL query or ibatis to obtain the result. when getObject () is used, the time, minute, and second are not displayed. It turns out that the JDBC driver automatically maps the date to java. SQL. date. If you use a 9i or 11g driver, you will find that there is no time, minute, and second. After Oracle9.2, the built-in data type TIMESTAMP is introduced. It is introduced because the minimum unit of the built-in data type DATE is second; the main problem of DATE is that its granularity cannot distinguish the first occurrence of two events. After version 9.2, ORACLE extended the TIMESTAMP data type on the DATE data type, which included information about all DATE data types, such as year, month, day, hour, minute, and second, and included decimal seconds (in the nanosecond Nanoseconds level). If you want to convert the DATE type to the TIMESTAMP type, use the CAST function. Since oracle 9.2, the built-in data types DATE and TIMESTAMP are mapped to java when the 9i JDBC driver is used for query. SQL. date and TIMESTAMP are mapped to java. SQL. timestamp. Since Oracle11, its JDBC driver re-starts regression to map the built-in type DATE to java. SQL. Timestamp (as before 9.2 ).
Therefore, the loss of accuracy in minutes and seconds is irrelevant to hibernate, which is a problem of the oracle jdbc driver. The best solution is:

[1] Change the driver. After testing, replace the first 10g driver ojdbc14.jar with the 11g driver ojdbc5.jar;

1.1: Apply the WEB-INFO/lib directory and Build Path references respectively.

1.2: If you are deploying a server application, you should also change the was configuration to ojdbc5.jar, as shown below:



PS: $ {ORACLE_JDBC_DRIVER_PATH} the path points to the was-environment-websphere variable where you can see the specific server configuration path;

[2] set date to the timestamp type in the database.

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.