This discussion is archived
3 Replies Latest reply: Sep 7, 2012 12:02 AM by 929890 RSS

Increasing spee to read Blob

929890 Newbie
Currently Being Moderated
Currently I a using
BLOB myBlob = ...
InputStream inputStream = new BufferedInputStream(myBlob.getBinaryStream(1L));
to read a Blob from a database table.

Is there a way to make reading out a Blob faster??
  • 1. Re: Increasing spee to read Blob
    rp0428 Guru
    Currently Being Moderated
    >
    Is there a way to make reading out a Blob faster??
    >
    No. You have to get the stream using the LOB locator.

    The slow speed in dealing with LOBs is because the actual data resides on the file system and when you read a LOB you are essentially causing Oracle to read a file.

    To read the LOBs for 10 records it is like reading 10 files one at at time from beginning to end. The larger each LOB is the longer it will take.

    See Reading and Writing BLOB, CLOB and NCLOB Data in the JDBC Developer's Guide
    http://docs.oracle.com/cd/B28359_01/java.111/b31224/oralob.htm#g1070326
    >
    Example: Reading BLOB Data
    Use the getBinaryStream method of the oracle.sql.BLOB class to read BLOB data. The getBinaryStream method provides access to the BLOB data through a binary stream.

    The following example uses the getBinaryStream method to read BLOB data through a byte stream and then reads the byte stream into a byte array, returning the number of bytes read, as well.

    // Read BLOB data from BLOB locator.
    InputStream byte_stream = my_blob.getBinaryStream(1L);
    byte [] byte_array = new byte [10];
    int bytes_read = byte_stream.read(byte_array);
    ...
  • 2. Re: Increasing spee to read Blob
    EJP Guru
    Currently Being Moderated
    Is there a way to make reading out a Blob faster??
    Faster than what? All you've shown us is the variable declarations. Where's the part that reads the BLOB?
  • 3. Re: Increasing spee to read Blob
    929890 Newbie
    Currently Being Moderated
    Well, I meant if there are faster ways to get the data using a Blob at all.
    But you're right: I should have told you how I read from the Blob after I got it. I am using an XMLStreamReader to read from the InputStream:
    XMLStreamReader xmlReader = createXMLStreamReader(inputStream, "UTF-8");
    while (xml.next() != START_ELEMENT) {
    ...
    }

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points