Home > Mobile >  Java ResultSet.getString() for Date field skips millisecond
Java ResultSet.getString() for Date field skips millisecond

Time:01-13

I am using ojdbc8 version 21.3.0.0 and am retrieving the Date column in Oracle as a string. I was expecting the string to be printed as 2021-01-21 00:00:00.0 but it prints as 2021-01-21 00:00:00 , so millisecond is skipped. Wondering why this change? Is there a way that getString() of ResultSet still return with millisecond, that's 2021-01-21 00:00:00.0 ?

ojdbc8 12.2 returned in this format 2021-01-21 00:00:00.0. With version upgrade this change is observed.

CodePudding user response:

In Oracle, a DATE is a binary data type stored as 7-bytes representing: century, year-of-century, month, day, hour, minute and seconds. The values are all integers so there will NEVER be any fractional seconds.

If you want fractional seconds then you need to use a TIMESTAMP data type.

If you want to display the time with fractional seconds then you will need to format the date and explicitly print the zero fractional seconds (which you could do by concatenating ".0" onto your string).

  • Related