Java.lang.ClassCastException: oracle.sql.BLOB cannot be passed to oracle.sql.BLOB

I have a problem retrieving a blob object from oracle DB in java API using jdbc. The problem is that when I execute the Collable statement with a function from db that returns the blob field to me, this exception is thrown on the line:

tempBlob = (oracle.sql.BLOB)cstmt.getObject(1);

with this error message:

 java.lang.ClassCastException: oracle.sql.BLOB cannot be cast to oracle.sql.BLOB. 

The object that I get from the database is an instance of oracle.sql.BLOB . TempBlob variable is an oracle.sql.BLOB object. Where is the problem?

+4
source share
4 answers

Two oracle jar files may be in your classpath. Remove one jar and unwrap it again.

+4
source

Once, one JAR is in the path of the application class, and the other is in the path of the application server class (for example: in Tomcat $CATALINA_HOME/lib )

+2
source

Do not throw again like:

 BLOB tempBlob = (oracle.sql.BLOB)cstmt.getObject(1); 

Decision:

 OutputStream outstrm =(rs.getBlob(1)).setBinaryStream(1L); 
0
source

I got this error while creating a jasper report.

I replaced class=oracle.jdbc.OracleBlob with class=java.sql.Blob in the jrxml file of this report. It worked for me.

0
source

All Articles