0

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;
    }
cp5
  • 1,087
  • 6
  • 26
  • 58
  • @Chrispie Can please attach table description – Siva Kumar Dec 18 '14 at 15:32
  • I added the following to my question (both the 2 fields I am reading is of type DATE with NULLABLE = false) – cp5 Dec 18 '14 at 15:34
  • 2
    @hfontanez - Did you actually read the question before claiming it's a duplicate? – Rudi Kershaw Dec 18 '14 at 15:34
  • It seems to me if we're to be able to help we need to know whats inside `JDBCConnection.getSqlObjectArray()` and which data types your `effFrom` and `effTo` columns are inside your DB. – Rudi Kershaw Dec 18 '14 at 15:51
  • Have you changed the jdbc driver? – Gren Dec 18 '14 at 16:03
  • @hfontanez I added what is in JDBCConnection.getSqlObjectArray(). There is not much happening there. But it is using sprring 2.5 to to the db call – cp5 Dec 19 '14 at 06:38
  • @Joachim We are using an oracle 11g DB with ojdbc14.jar driver. This has not been upgraded in the last 2years – cp5 Dec 19 '14 at 07:23

0 Answers0