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

Discussion in 'Java' started by arashamiri@hotmail.com, Nov 8, 2005.

  1. Guest

    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.
     
    , Nov 8, 2005
    #1
    1. Advertising

  2. 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
     
    David Zimmerman, Nov 8, 2005
    #2
    1. Advertising

  3. Roedy Green Guest

    On 8 Nov 2005 07:37:54 -0800, wrote, quoted or
    indirectly quoted someone who said :

    >
    >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.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Nov 9, 2005
    #3
  4. Guest

    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:

    > On 8 Nov 2005 07:37:54 -0800, wrote, quoted or
    > indirectly quoted someone who said :
    >
    > >
    > >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.
    > --
    > Canadian Mind Products, Roedy Green.
    > http://mindprod.com Java custom programming, consulting and coaching.
     
    , Nov 9, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vizlab
    Replies:
    3
    Views:
    7,508
    satya
    Aug 26, 2007
  2. hiwa
    Replies:
    1
    Views:
    613
    Ryan Stewart
    Dec 29, 2004
  3. gwinsor
    Replies:
    1
    Views:
    667
    timjowers
    Jul 2, 2007
  4. Shalz
    Replies:
    0
    Views:
    654
    Shalz
    Mar 8, 2008
  5. laredotornado
    Replies:
    2
    Views:
    2,853
    Mittal
    Sep 28, 2012
Loading...

Share This Page