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

家住魔仙堡 提交于 2019-12-01 04:51:39

问题


I have problem retrieving a blob object from oracle DB to java API with jdbc. The problem is when I execute a Collable statement with a function from the db which return me a blob field 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 which I get from the DB is a instance of oracle.sql.BLOB. The tempBlob variable is a object oracle.sql.BLOB. Where is the problem?


回答1:


Two oracle jar files may be in your classpath. Please remove one jar and deploy again.




回答2:


Sometime one JAR is in the application classpath and another is in the application server classpath (eg.: in Tomcat $CATALINA_HOME/lib)




回答3:


Dont Cast again like:

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

Solution :

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



回答4:


I got this error while generating a jasper report.

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



来源:https://stackoverflow.com/questions/11411306/java-lang-classcastexception-oracle-sql-blob-cannot-be-cast-to-oracle-sql-blob

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!