Store a Blob from Java to BD: Data size bigger than max size for this type when is clearly not

大憨熊 提交于 2019-12-11 08:26:15

问题


Ok, here we go...

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: Data size bigger than max size for this type

That is oh so very frustrating..

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

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

I get the same error with:

oracleCallableStatement.setBytes(3, someByteArray);

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

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

But the problem is persistent

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

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

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

Portion of the stack trace:

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)

EDIT

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

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

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

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... Usage of the classes in sun.misc is not recommended, read this for further information..

work sun.misc.BASE64Encoder/Decoder for getting byte[]

BUT!!!

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" ...

EDIT:

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...

EDIT:

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


回答1:


Not the answer

You cannot keep the bytes of an image in a String (correctly). You could first encode the byte[] using Base64 into a String. Maybe though I misunderstand, and you did it correctly. Check that you did log every exception.

There are some other Base64 conversions besides the deprecated sun's version (which is not available in every JDK). In JavaEE:

import javax.xml.bind.DatatypeConverter;
String data = "...";
byte[] bytes = DatatypeConverter.parseBase64Binary(data);
String data = DatatypeConverter.parseBase64Binary(bytes);

Can't you store the data as binary blob, without base64 encoding? It'd at least save space.

An other error could be growing reused ByteArray's or something other trivial bug.




回答2:


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.



来源:https://stackoverflow.com/questions/14859758/store-a-blob-from-java-to-bd-data-size-bigger-than-max-size-for-this-type-when

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