Oracle JDBC Types Mapped to Java Object Types by getObject() - wrong document?
Asked Answered
S

1

6

this is the document link: "Mapping SQL and Java Types"

let's see 8.9.3 JDBC Types Mapped to Java Object Types at row: TIMESTAMP - java.sql.Timestamp

but when I use getObject() with oracle database on a TIMESTAMP column, the return type is oracle.sql.TIMESTAMP, it can not been cast to java.sql.Timestamp

I know that I can use getTimestamp() but I need getObject() for handling any resultset regardless of types.

Is the document wrong or me?

Sanson answered 30/1, 2013 at 4:5 Comment(1)
alberlau.blogspot.ru/2008/01/…Georgiannageorgianne
S
3

The document is correct, the Oracle JDBC driver is the problem.

There's 2 possible solutions:

First one, use getObject:

oracle.sql.TIMESTAMP ts = (oracle.sql.TIMESTAMP) res.getObject("last_update");
agent.setLastUpdate(new Date(ts.dateValue().getTime()));

The second is to add a VM argument to your app:

-Doracle.jdbc.J2EE13Compliant=true

This will make the driver return java.sql.Timestamp instead of oracle.sql.TIMESTAMP.

Spongin answered 13/2, 2013 at 20:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.