Subject Re: [Firebird-Java] FB Blob problem - OutOfMemory
Author Rick Fincher
Hi Phil,

If you use a ResultSet with autocommit mode on, the entire thing gets
returned at once uses all the memory available for Java that the JDBC
driver is running in. Turn off autocommit and give it a try.

Be aware, though, that you must have enough memory allocated to the JVM
to read the largest graphic you will ever retrieve or you will get the
OOM exception. You may not be able to guarantee this if your app gets
deployed elsewhere.

The size problem is probably a result of padding the buffers in the
stream/blob reads. You can get around that by storing the image size in
a field of the record, then reading the size upon retrieval of the
image, and only reading that number of bytes from the stream and putting
them in the image.

It is also helpful to store info like mime-type, creation date, original
filename, etc. if you might ever need to access the image through a web
app or store it back to disk as a file.

Hope this helps,

Rick

phil_hhn wrote:
>
> Hi,
> I've come across an issue, using FB 1.5.3.
>
> I have a JDBC connection to a Firebird (FB) database and an SQL Server
> (SS) database. I ran a query against FB, returning a Blob (in this
> case originally a 20k PNG image on disk) that I want to insert into SS
> (via a PreparedStatement). So I ran ResultSet.getBlob, then
> PreparedStatement.setBlob. The blob (i.e the 20k PNG image) can be
> retrieved from SS and viewed ok.
>
> The problem arises when I try to run this code with lots of large
> blobs (i.e several MB each) - something causes an OutOfMemory
> exception (seems to be the JDBC driver).
> So I changed the code to read the data from FB via an InputStream and
> insert directly into SS. This does not run out of memory. I also tried
> using getBytes... setBytes. In each of these the data processed (in my
> small test case above) appears to be 25K, not 20k. I.e if I call
> Blob.length() it returns 25k. So when I retrieve the data from SS, it
> is not a valid PNG image.
>
> I am confused - the getBlob...setBlob routines would be ideal to use
> if I did not get the OutOfMemory exception, and the other code (using
> streams or the low-level byte routines) appear to give spurious
> results. Can anyone shed light on this problem, or suggest what the
> issue might be?
>
> Thanks,
> Phil
>
>
>