javaclasscastexceptioncachedrowset

Caused by: java.lang.ClassCastException: java.sql.Timestamp cannot be cast to java.sql.Date


I am getting the below given error for the following code snippets:

  try {
        cRows = new CachedRowSetImpl();
        while(cRows.next()) 
        {
        MyClass myClass = new MyClass();
        myClass.setPrevDate(cRows.getDate("PREV_DATE")); // In debug mode, the error was throwing when I press Resume from here.
        }
      }

Error:

Caused by: java.lang.ClassCastException: java.sql.Timestamp cannot be cast to java.sql.Date

In the database, the datatype for the column is DATE only. I am not able to figure out where the Timestamp is coming here.


Solution

  • I have done a research on this issue and found some useful links. I found this confusion between DATE and TIMESTAMP is JDBC Driver specific. And most of the links suggest the use of -Doracle.jdbc.V8Compatible=true. For my JBoss I have set this in run.bat and the issue got resolved.

    1. https://community.oracle.com/thread/68918?start=0&tstart=0

    2. http://www.coderanch.com/t/90891/JBoss/oracle-jdbc-Compatible-true

    3. https://community.oracle.com/message/3613155

    The oracle doc shares different solutions:

    Here is the link: http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-faq-090281.html#08_00