Because of this magics it's possible to spend whole day while finding solution. The problem was
java.lang.ClassCastException: oracle.sql.TIMESTAMP cannot be cast to java.sql.Timestamp on Tomcat, while on OC4J application was running fine. As I supposed ResultSet was returning oracle.sql.TIMESTAMP instead of java.sql.Timestamp. If oracle.sql.TIMESTAMP were extending java.sql.Timestamp there would be no problem. But it extends
oracle.sql.Datum. I tried different Oracle JDBC versions, starting from
classes12.jar ending ojdbc6.jar . The problem remains unsolved. After deeper research i found that Oracle JDBC uses
oracle.jdbc.J2EE13Compliant property to determine what to return : oracle.sql.TIMESTAMP or java.sql.Timestamp. In case when this property is false, Oracle JDBC becomes not JDBC compatible, because
oracle.jdbc.driver.TimestampAccessor returns oracle.sql.TIMESTAMP. There is some abstract info about oracle.jdbc.J2EE13Compliant in
Oracle JDBC FAQ . There is more issues related to this property. In case of oracle.jdbc.J2EE13Compliant==true and precission not equals zero and scale is minus 127
oracle.jdbc.driver.NumberCommonAccessor returns
Double in other cases it will return
BigDecimal . The fastest and easest way to solve this problem is to add
-Doracle.jdbc.J2EE13Compliant=true to your Tomcat or any other "not J2EE13Compliant" application server startup properties. It's a strange ways to get compatibilities :)
Labels: java.lang.ClassCastException, java.sql.Timestamp, JDBC, Oracle, oracle.jdbc.J2EE13Compliant, oracle.sql.TIMESTAMP