Hi!
I have following problem:
We store java classes in oracle (version 10g) blob fields, in order to
load them later with a special classloader using ojdbc14 drivers.
I use the following way to obtain a class:
<snip>
BLOB blob = ((OracleResultSet) rs).getBLOB(someBlobFieldName);
byte[] b = blob.getBytes(1,blob.length());
</snip>
my problem is that by trying to convert the byteArray to a class in a
classloader, I receive following error:
java.lang.ClassFormatError: ... (Extra bytes at the end of the class
file)
When I print the blob to the screen, I see a lot of zeros at the end,
which I suppose are the problem.
How can I trim the blob to a correct size depending on the class it
contains????
please, please, help.
arash.
David Zimmerman - 08 Nov 2005 23:46 GMT
arashamiri@hotmail.com wrote:>
> java.lang.ClassFormatError: ... (Extra bytes at the end of the class
> file)
>
> When I print the blob to the screen, I see a lot of zeros at the end,
> which I suppose are the problem.
I bet your problem is where the class bytes are getting put into the BLOBs
Roedy Green - 09 Nov 2005 03:22 GMT
>How can I trim the blob to a correct size depending on the class it
>contains
Who put the class in there? They are the one at fault. They may have
used a fixed size buffer zero padded.
If it turns out Oracle has a bug, tell them and in the meantime
prepend a length count. When you fish it out, use that to trim the
size of what you use in your classloader.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
arashamiri@hotmail.com - 09 Nov 2005 12:13 GMT
ok, thanks people.
solved it.
It was indeed a problem of the "setBlob()" method.
if anyone is interested:
to read a blob from an InputStream "in" and write it to an oracle 10g
database use this:
<snip>
byte[] binaryBuffer;
long position;
int bytesRead = 0;
int bytesWritten = 0;
try {
binaryBuffer = new byte[in.available()];
position = 1;
while ( (bytesRead = in.read(binaryBuffer)) != -1) {
bytesWritten = blob.putBytes(position, binaryBuffer);
position += bytesRead;
}
} catch (Exception e) {
e.printStackTrace();
}
oraclepreparedstatement = (OraclePreparedStatement)
con.prepareStatement( sql );
oraclepreparedstatement.setBLOB(1, blob);
oraclepreparedstatement.executeUpdate();
blob.close();
</snip>
Roedy Green schrieb:
> >How can I trim the blob to a correct size depending on the class it
> >contains
[quoted text clipped - 8 lines]
> Canadian Mind Products, Roedy Green.
> http://mindprod.com Java custom programming, consulting and coaching.