oracle10g Get Date Type field no-time/minute-seconds solution!

Source: Internet
Author: User

In a generic database, the Date field represents only the dates, not the date information, and the date data types in the Oracle database are dates, times, and for different versions of the Oracle JDBC driver, there are some differences in the handling of the problem.

recently using ORACLE 10G, Time field due to the requirements, set to date type, found hibernate with native SQL query or Ibatis get Result.getobject () when the time is not displayed seconds, it is the JDBC driver automatically map date to Java.sql.date, so truncated time-division seconds information, if you use 9i or 11g  driver, there is no problem, but oracle10g JDBC driver, you will find that there are no seconds, After Oracle9.2, the built-in data type timestamp is introduced. It is introduced because the smallest unit of the built-in data type date is seconds; the main problem with date is that it does not have enough granularity to distinguish between two events which first occur. After version 9.2, Oracle extended the timestamp data type on the date data type, which includes information for all date data types, months and seconds, and includes information for fractional seconds (nanosecond nanoseconds level). If you want to convert the date type to a timestamp type, use the cast function.   is also starting with Oracle 9.2, with built-in data types date and timestamp are mapped to java.sql.Date when querying with the JDBC driver of 9i. The Timestamp is mapped to Java.sql.Timestamp.   Starting with ORACLE11, its JDBC driver restarts back to map the built-in type date to Java.sql.Timestamp (as before 9.2).  
Therefore, the loss of precision and seconds is not related to hibernate, which is the problem of Oracle JDBC driver. The best solution is:

"1" Change drive. After testing, the first use of the 10g drive Ojdbc14.jar for 11g Drive Ojdbc5.jar;

1.1: Apply Web-info/lib directory and build path reference respectively.

1.2: If you are deploying a server application, you should also change the configuration of was to Ojdbc5.jar, as follows:



Ps:${oracle_jdbc_driver_path} path pointing at the was-environment-websphere variable can see the specific server configuration path;

" 2 " Set date to timestamp type.

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.