Bug #84059 | Driver is stripping off fractional part of TIME when calling ResultSet.getObject | ||
---|---|---|---|
Submitted: | 5 Dec 2016 11:26 | Modified: | 27 Dec 2016 8:56 |
Reporter: | kriti suwalka | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | Connector / J | Severity: | S2 (Serious) |
Version: | 6.0.5 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[5 Dec 2016 11:26]
kriti suwalka
[5 Dec 2016 13:11]
Chiranjeevi Battula
Hello kriti suwalka, Thank you for the bug report. The result of rs.getObject(col+1) is returning a java.sql.Time#toString() instance, so when you going to prints it, it just gets the toString() of it and it doesn't mean the milliseconds value isn't there, it just doesn't show. To get those values have to use a custom DateFormat like SimpleDateFormat("HH:mm:ss.SSS"). Thanks, Chiranjeevi.
[19 Dec 2016 6:48]
kriti suwalka
Thanks for your response :) I am using below code now String pattern = "HH:mm:ss.SSS"; SimpleDateFormat simpledate = new SimpleDateFormat(pattern); simpledate = (SimpleDateFormat) rs.getObject(col+1); But it is throwing exception "java.sql.Time cannot be cast to java.text.SimpleDateFormat". As per my requirement we need to read this time field from our source table and insert the value in our target table. But when we read it using getObject(), it does not read fractional part hence the value inserted in target table too does not have fractional part. It would be great if you could tell us how can we read time field so it does not truncate fractional part. Please note that in case of datetime field, it reads as expected. I wonder why it is not reading properly in case of time field.
[20 Dec 2016 12:26]
Chiranjeevi Battula
Hello kriti suwalka, Thank you for the bug feedback. I could not repeat the issue at our end using with Connector/Java 6.0.5 version. String strDate = new SimpleDateFormat("HH:mm:ss.SSS").format(rs.getTime(col+1)); System.out.println(strDate); This doesn't work with C/J 5.1 due to legacy limitations, but you can still do the following to achieve the same result String strDate = new SimpleDateFormat("HH:mm:ss.SSS").format(rs.getTimestamp(col+1)); System.out.println(strDate); Thanks, Chiranjeevi.
[27 Dec 2016 8:05]
kriti suwalka
Thanks Chiranjeevi :)
[27 Dec 2016 8:56]
Chiranjeevi Battula
Thank you for the bug feedback.