Tags: asking, calling, column, connectivity, database, driver, getobject, instead, jar, java, javasqltimestamp, jdbc, ojdbc14, oraclesqltimestamp, returns, rowset, version
getObject() returns oracle.sql.TIMESTAMP instead of java.sql.Timestamp
We are using the ojdbc14.jar driver to talk to a 10.1.0.4 version database. When calling getObject() on a rowset, asking for a column that has database type TIMESTAMP(9), I expect to get a java.sql.Timestamp. Instead, I get an oracle.sql.TIMESTAMP, which cannot be casted to java.sql.Timestamp.
Reading the Oracle forums and manuals, I get the impression that the default mapping should be to the java.sql.* types - if possible - and that mapping to oracle.sql.* types is optional.
Can anyone shed some light on this? What is the default mapping and how can it be influenced? Any help would be greatly appreciated.
Leave a comment...
- 5 Comments
- This is something that is bugging me as well for quite some time. The date/timestamp handling in Oracle's JDBC driver has never been optimal (maybe because the timestamp handling has been implemented so late in the Server as well).
My only workaround is to use getTimestamp() instead. One would think that the two would return objects of the same class, but apparently getTimestamp() works as expected.#1; Sat, 23 Feb 2008 12:35:00 GMT
- Wherever we can we are already using getTimestamp(), but in some cases this is not an option, as the recordset is stored in Java objects before their type is known. Funny thing is that before the TIMESTAMP database type was introduced, the DATE database type returned java.sql.Timestamp.
Before I implement explicit translations instead of the normal casts I would like to make sure there is no simple, clean solution to the problem.#2; Sat, 23 Feb 2008 12:36:00 GMT
- > Wherever we can we are already using getTimestamp(),
> but in some cases this is not an option, as the
> recordset is stored in Java objects before their type
> is known.
Been there too :)
What I do is to get the ResultSetMetadata and while iterating over the columns and calling getObject() I'm checking for the java.sql.Types.DATE or java.sql.Types.TIMESTAMP data type and in that case I call getTimestamp() instead of getObject(). An ugly hack but I could not find a different solution to work around this driver bug. This seems to work with other databases as well (e.g. Postgres)#3; Sat, 23 Feb 2008 12:37:00 GMT
- This is a problem for me too, and seems to directly contradict the table 11.1 in the 10g docs which says that if the SQL type is TIMESTAMP the getObject method will return java.sql.Timestamp and getOracleObject method will return oracle.sql.TIMESTAMP.
Means that we can't write portable Java code that will work with Oracle. Their loss (if only...).#4; Sat, 23 Feb 2008 12:38:00 GMT
- have you tried adding the oracle connection property:
java.util.Properties prop = new java.util.Properties ();
prop.put ("oracle.jdbc.V8Compatible", "true"); // so getObject returns Timestamp!
prop.put ("user", "scott");
prop.put ("password", "tiger");
String url ="jdbc:oracle:thin:.jdbc.developerfaqs.com.host:port:sid";
Connection conn = DriverManager.getConnection (url,prop);
Let me know,,,
Joe Weinstein at BEA Systems#5; Sat, 23 Feb 2008 12:39:00 GMT