将 Blob 从 Java 存储到 BD:数据大小大于此类型的最大大小时显然不是 [英] Store a Blob from Java to BD: Data size bigger than max size for this type when is clearly not

查看:26
本文介绍了将 Blob 从 Java 存储到 BD:数据大小大于此类型的最大大小时显然不是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我们开始......

Ok, here we go...

我正在尝试调用存储过程 (PL/SQL),其中一个参数是 blob,但是当我执行 OracleCallableStatement 时出现此错误:

I am trying to call a Stored Procedure (PL/SQL), one of the parameters is a blob, but when I execute the OracleCallableStatement I get this error:

java.sql.SQLException: 数据大小大于此类型的最大大小

那真是太令人沮丧了..

That is oh so very frustrating..

我尝试执行以下操作但失败了...

I have tried to do the following and fails...

oracleCallableStatement.setBinaryStream(3, new ByteArrayInputStream(someByteArray), someByteArray.length);

我遇到了同样的错误:

oracleCallableStatement.setBytes(3, someByteArray);

我也更改了 oracle 驱动程序,因为我阅读了这样的网页:

I also changed the oracle driver, since I read web pages like this:

http://www.coderanch.com/t/457770/JDBC/databases/java-sql-sqlexception-data-size

说有bug,我更新到ojdbc5.jar来自:http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html

Says that there's a bug, I updated it to ojdbc5.jar From: http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html

但问题一直存在

数据库是 Oracle 11gJavaEE 是运行在 Glassfish 2.1 中的 1.5

The DB is an Oracle 11g JavaEE is 1.5 running in Glassfish 2.1

好吧,我想就是这样,我的 someByteArray 不大于 4Gb!它的长度为 38678

Well, I guess that's it, my someByteArray is not bigger than 4Gb! it has a length of 38678

异常在执行之前触发.当我为 OracleCallableStatement 设置属性时触发它

The exception is firing before the execute.. it fires when I set an attribute for the OracleCallableStatement

堆栈跟踪的一部分:

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:179)
at oracle.jdbc.ttc7.TTCItem.setArrayData(TTCItem.java:103)
at oracle.jdbc.dbaccess.DBDataSetImpl.setBytesBindItem(DBDataSetImpl.java:2484)
at oracle.jdbc.driver.OraclePreparedStatement.setItem(OraclePreparedStatement.java:1224)
at oracle.jdbc.driver.OraclePreparedStatement.setBinaryStream(OraclePreparedStatement.java:2710)

编辑

再次,你好,把这个放在这里...告诉我如果我做错了,我会删除它...

So, hello again, going to put this here... tell me if I´m doing wrong and I will delete it...

someByteArray 是从 someString.toByteArray() 获取的数组

someByteArray was an array that was get from a someString.toByteArray()

那个字符串保存了一个(用于说 jpeg)以 Base64 编码的 PNG 图像的表示......

That String was holding a representation of a ( used to say jpeg) PNG image encoded in Base64...

所以,我使用了 sun.misc.BASE64Decoder 中的一个方法从 someString 中获取 someByteArray...然后我用了

So, I used a method in sun.misc.BASE64Decoder to get the someByteArray from the someString... then I used

oracleCallableStatement.setBinaryStream(3, new ByteArrayInputStream(someByteArray), someByteArray.length);

它的作用就像一个魅力..

And it worked like a charm..

BUUUT...不推荐使用 sun.misc 中的类,请阅读本文以获取更多信息..

BUUUT... Usage of the classes in sun.misc is not recommended, read this for further information..

工作 sun.misc.BASE64Encoder/Decoder 获取字节[]

但是!!!

这并没有解决为什么我无法将第一个字节数组放入参数的谜团以及神秘异常java.sql.SQLException:数据大小大于此类型的最大大小"的谜团..

That doesn't solve the mystery to why I was unable to put the first byte array into the parameters and the mystery of the cryptic exception "java.sql.SQLException: Data size bigger than max size for this type" ...

此错误再次出现...这次一切正常,我正确解码了 base64,但是java.sql.SQLException:数据大小大于此类型的最大大小"不断返回...

This error appeared again... this time everything was alright, I was decoding the base64 correctly, but "java.sql.SQLException: Data size bigger than max size for this type" kept returning...

这是驱动程序,我在服务器和应用程序上对其进行了更改,然后重新部署,一切正常...

It was the driver, I change it on the server and the app, and I redeployed and everything worked fine...

推荐答案

原来是驱动,我改成 ojdbc5.jar,正如我在问题中所说的,我必须确保 Web 服务器选择了正确的正如 Alex Poole 所指出的那样,一个而不是旧的,问题解决了.

Turns out it was the driver, I changed to ojdbc5.jar as I stated in my question, and I had to make sure that the web server picked the correct one and not the older one, as pointed by Alex Poole, and problem solved.

这篇关于将 Blob 从 Java 存储到 BD:数据大小大于此类型的最大大小时显然不是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆