ClassCastException: Cannot cast java.sql.Date (id=9010) to java.sql.Timestamp

564 views Asked by At

I am having a problem with a Java 1.4 app.

I am executing a JDBC Qyery-which is 2 date fields in an Oracle database (both the 2 fields I am reading is of type DATE with NULLABLE = false)

SELECT effFrom, effTo FROM myTable WHERE ....

And is exceuted with a JDBCConnection

Object[][] result = JDBCConnection.getSqlObjectArray(query, bindVals);

I get the data back in my result and loop through it

for (int i = 0; i < result.length; i++) {
 java.sql.Timestamp effFrom = (java.sql.Timestamp ) result[i][0];
 java.sql.Timestamp effTo = (java.sql.Timestamp ) result[i][1];

but it fails converting the object to a java.sql.Timestamp with the error ClassCastException: Cannot cast java.sql.Date (id=9010) to java.sql.Timestamp

(java.sql.Timestamp ) result[i][0]

So I changed the convertion to

java.sql.Date effFrom = (java.sql.Date) result[i][0];

And it is working. All perfect.

But the thing is that my code did not change and the data did not change for the last 6 months atleast.

It did work with the Timestamp conversion up to yesterday and today it is not working with the timestamp but with the Date.

I then went back to the source code repo and seen that it was originally java.sql.Date about 2 years ago and now I basically rolled it back. So clearly there is something that I am missing here.

Is there a way that the JDBC query could mis interpret the data type?

As per Rudi's question what is inside JDBCConnection.getSqlObjectArray()

It has a JdbcDaoSupport class called dao

 public static Object[][] getSqlObjectArray(String sql, String bind1, String bind2, String bind3) {

        Object[][] a = dao.getSqlObjectArrayImpl(sql, bind1, bind2, bind3);
        return a;
    }
0

There are 0 answers