0

I am facing a unique problem.

I am querying a database field which has a datatype (in oracle) as DATE . I am retrieving the value from resultSet as rs.getObject("myDate") . We have two setups which have identical configuration . On one setup when I write rs.getObject("myDate").getClass() , I am geeting java.sql.TimeStamp and on another setup it is returning java.util.Date. The problem I am facing is when it returns an object of date it is ignoring the time and returning only the date part.

1
  • Are the database columns identical, type + length definition? Commented Jul 20, 2011 at 15:45

2 Answers 2

1

I think this behaviour can be controlled using this connection property:

oracle.jdbc.mapDateToTimestamp

See this forum thread, for instance:

http://forums.oracle.com/forums/thread.jspa?threadID=483903

Sign up to request clarification or add additional context in comments.

Comments

0

als info: java.sql.Timestamp IS a java.util.Date as it extends it.

Dates also have time, though it does not have nanoseconds, that's the only difference.

Sadly enough, that's the way it is implemented, but not the way it should be. From their own docs:

The inheritance relationship between Timestamp and java.util.Date really denotes implementation inheritance, and not type inheritance. https://docs.oracle.com/javase/7/docs/api/java/sql/Timestamp.html

which means they were to lazy to write some encapsulation. This causes many quirks, like hashcodes not changing for nanoseconds and asymmetrical equals.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.