HELP! storing java class in oracle blob problem --> classFormatError!!!

A

arashamiri

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

David Zimmerman

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
 
R

Roedy Green

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

arashamiri

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top