使用图像文件更新 Oracle BLOB
这就是我想要做的:
- 从 oracle BLOB 读取图像
- ,调整其大小,
- 将调整大小的图像写回到表中(更新 blob 本身)。
我的表如下所示:
TECHID NOT NULL NUMBER(12)
MEDIADATA NOT NULL BLOB()
INSERTEDDATE NOT NULL DATE
MODIFIEDDATE NOT NULL DATE
步骤 1 和 2 完美运行。步骤 3 的代码如下(这是 PoC 类型的尖峰解决方案 - 不是最终生产):
File resized = get the resized image FileInputStream fis = new FileInputStream(resized) PreparedStatement p = db.connection.prepareStatement("update mymediadata set mediadata = ? where TECHID=142") if (fis != null) { println("Available: ${fis.available()}"); // this works - shows 117K bytes available. } p.setBinaryStream (1, fis, resized?.length()?.intValue()) try { p.executeUpdate() } catch (Exception e) { e.printStackTrace() } finally { p.close() fis.close() }
当我到达步骤 3 时,出现以下错误:
SQLException: ORA-01407: 无法更新 ("OWNER"."MEDIADATA "."MEDIADATA") 为 NULL
我明确检查(在调试器中)FileInputStream (fis) 不为空。我还检查了 resized?.length()?.intValue()
值也 > 0.所以我正在努力想知道我可能做错了什么。
技术栈:
Groovy GDK 1.7 爪哇1.5 Oracle 10g
在 32 位 Windows XP 上运行。
This is what I am trying to do:
- Read an image from the oracle BLOB
- Resize it
- Write the resized image back to the table(update the blob itself).
My table looks like this:
TECHID NOT NULL NUMBER(12)
MEDIADATA NOT NULL BLOB()
INSERTEDDATE NOT NULL DATE
MODIFIEDDATE NOT NULL DATE
Steps 1 and 2 work perfectly. The code for step 3 is as follows (this is a PoC type spike solution - not final production):
File resized = get the resized image FileInputStream fis = new FileInputStream(resized) PreparedStatement p = db.connection.prepareStatement("update mymediadata set mediadata = ? where TECHID=142") if (fis != null) { println("Available: ${fis.available()}"); // this works - shows 117K bytes available. } p.setBinaryStream (1, fis, resized?.length()?.intValue()) try { p.executeUpdate() } catch (Exception e) { e.printStackTrace() } finally { p.close() fis.close() }
When I get to step 3, I get the following error:
SQLException: ORA-01407: cannot update ("OWNER"."MEDIADATA"."MEDIADATA") to NULL
I explicitly checked (in debugger) that the FileInputStream (fis) is not null. I also checked that the resized?.length()?.intValue()
value is also > 0. So I am struggling to see what I might be doing wrong.
Technology stack:
Groovy GDK 1.7
Java 1.5
Oracle 10g
Running on 32 bit Windows XP.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我终于成功解决了这个问题。事实证明,是一个狡猾的 JDBC oracle 驱动程序(显然是早期版本)导致了这些错误。
一旦我切换到正确的版本,错误就消失了!
OK, I finally managed to resolve this. It turns out it was a dodgy JDBC oracle driver (apparently an earlier version) which was causing the errors.
As soon as I switched to the proper version, the error vanished!