为什么我无法从本机 java Blob 转换 oracle BLOB

发布于 2024-07-10 08:47:01 字数 316 浏览 6 评论 0原文

我正在从 ResultSet 读取文件,需要将文件保存到 Oracle 数据库中。

...
ResultSet rs = ...
java.sql.Blob myfile = rs.getBlob("field")
java.io.OutputStream os = ((oracle.sql.BLOB) myfile).getBinaryOutputStream();

我收到此错误消息

java.lang.ClassCastException

有人有解决方案吗? 谢谢!

I am reading file from ResultSet and it's required to save file into Oracle Database.

...
ResultSet rs = ...
java.sql.Blob myfile = rs.getBlob("field")
java.io.OutputStream os = ((oracle.sql.BLOB) myfile).getBinaryOutputStream();

I get get this error message

java.lang.ClassCastException

Any one have solution to this? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

极致的悲 2024-07-17 08:47:01

我已经找到了解决方案。 我想与有这个问题的人分享。

从oracle blob获取outputstream的代码是:

java.io.OutputStream os = ((oracle.sql.BLOB) myBlob).setBinaryStream(1L);

setBinaryStream()实际上是返回java.io.OutputStream对象

I have found the solution. I'd like to share with those who has this problem.

The code to get outputstream from oracle blob is:

java.io.OutputStream os = ((oracle.sql.BLOB) myBlob).setBinaryStream(1L);

setBinaryStream() is actually returning java.io.OutputStream object

甜扑 2024-07-17 08:47:01

java.sql.Blob 是一个接口。 大概 ResultSet 中返回的实现与 oracle.sql.BLOB 不同?

myfile.getClass() 返回什么?

java.sql.Blob is an interface. Presumably the implementation returned in your ResultSet is a different implementation to oracle.sql.BLOB?

What does myfile.getClass() return?

牵你的手,一向走下去 2024-07-17 08:47:01

你似乎没有 oracle.sql.BLOB 在那里(如果你有,它应该工作,BLOB 实现 Blob)。 ClassCastException 说的是什么?

您使用的是哪个版本的 Oracle 以及哪个版本的 JDBC 驱动程序?

无论如何,getBinaryOutputStream 已被弃用,您应该在 JDBC (3.0) 接口中使用 setBinaryStream,这可能根本不需要访问 Oracle 的内部类。

You seem to not have an oracle.sql.BLOB there (if you did, it should work, BLOB implements Blob). What does the ClassCastException say it is?

What version of Oracle and what version of the JDBC driver are you using?

getBinaryOutputStream is deprecated anyway, you should use setBinaryStream in the JDBC (3.0) interface, which probably removes the need to go to Oracle's internal class at all.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文