java.lang.ClassCastException: oracle.sql.TIMESTAMP cannot be cast to java.sql.Timestamp

后端 未结 7 1250
梦谈多话
梦谈多话 2020-12-29 04:39

I am working on an application that streams ResultSet over a network. I ended up using a CachedRowSetImpl class. But when I connect to an Oracle DB, I get an error like this

7条回答
  •  余生分开走
    2020-12-29 05:10

    This is because oracle.sql.TIMESTAMP is not derived from java.sql.TIMESTAMP:

    java.lang.Object
      -> oracle.sql.Datum
         -> oracle.sql.TIMESTAMP
    

    You can't cast the former into the later.

    Instead use oracle.sql.TIMESTAMP.timestampValue():

    public Timestamp timestampValue(Calendar cal) throws SQLException
    

    Calls toTimestamp to convert internal Oracle Date and Calendar to a Java Timestamp.

提交回复
热议问题