Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to convert an OracleDB DATE to java.sql.Time via native Query?

cadb4231-e3b6-4b3b-8937-1860574957c6Nov 6 2017 — edited Nov 6 2017

Hello,

I am trying to receive a time that is saved in a DATE column. This is how I fetch the data in my Java code:

    Query query = entityManager.createNativeQuery(SELECT_DATETIME);

    Object[] dates = (Object[]) query.getSingleResult();

The dates are of the type java.sql.Date, but Date does not contain the time that was saved in the DATE column of my database. Is there any way to tell the database or Java to create java.sql.Time objects instead?

Best regards and thanks in advance.

Comments
Post Details
Added on Nov 6 2017
1 comment
1,694 views