java.lang.ClassCastException: oracle.sql.BLOB 不能转换为 oracle.sql.BLOB
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11411306/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.ClassCastException: oracle.sql.BLOB cannot be cast to oracle.sql.BLOB
提问by Jordan Borisov
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 :
我在使用 jdbc 将 blob 对象从 oracle DB 检索到 java API 时遇到问题。问题是当我使用 db 中的函数执行 Collable 语句时,该函数返回一个 blob 字段,该异常在行上抛出:
tempBlob = (oracle.sql.BLOB)cstmt.getObject(1);
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?
我从数据库中得到的对象是oracle.sql.BLOB
. tempBlob 变量是一个对象oracle.sql.BLOB
。问题出在哪儿?
采纳答案by Sai Ye Yan Naing Aye
Two oracle jar files may be in your classpath. Please remove one jar and deploy again.
两个 oracle jar 文件可能在您的类路径中。请删除一个 jar 并重新部署。
回答by Frizz1977
Sometime one JAR is in the application classpath and another is in the application serverclasspath (eg.: in Tomcat $CATALINA_HOME/lib
)
有时一个 JAR 在应用程序类路径中,另一个在应用程序服务器类路径中(例如:在 Tomcat 中$CATALINA_HOME/lib
)
回答by Mohamed Maidheen
Dont Cast again like:
不要再次投射,例如:
BLOB tempBlob = (oracle.sql.BLOB)cstmt.getObject(1);
Solution :
解决方案 :
OutputStream outstrm =(rs.getBlob(1)).setBinaryStream(1L);
回答by Vinay
I got this error while generating a jasper report.
生成 jasper 报告时出现此错误。
I replaced the class=oracle.jdbc.OracleBlob
with class=java.sql.Blob
in the jrxml file of that report. It worked for me.
我更换了class=oracle.jdbc.OracleBlob
与class=java.sql.Blob
该报告的JRXML文件。它对我有用。