Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
arashamiri@hotmail.com - 08 Nov 2005 15:37 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.