X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3709CD80AB for ; Tue, 30 Aug 2005 13:14:50 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 98564-07 for ; Tue, 30 Aug 2005 16:14:47 +0000 (GMT) Received: from relais.videotron.ca (relais.videotron.ca [24.201.245.36]) by svr1.postgresql.org (Postfix) with ESMTP id C1017D7337 for ; Tue, 30 Aug 2005 13:14:46 -0300 (ADT) Received: from [24.202.239.89] by VL-MO-MR002.ip.videotron.ca (Sun Java System Messaging Server 6.2-2.05 (built Apr 28 2005)) with ESMTP id <0IM100LOIMGLN4C0@VL-MO-MR002.ip.videotron.ca> for pgsql-jdbc@postgresql.org; Tue, 30 Aug 2005 12:14:45 -0400 (EDT) Date: Tue, 30 Aug 2005 12:14:45 -0400 From: Oscar Picasso Subject: Blob and unknown length To: pgsql-jdbc@postgresql.org Reply-To: oscpro@videotron.ca Message-id: <431485F5.1010407@videotron.ca> MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7BIT X-Accept-Language: en-us, en User-Agent: Mozilla Thunderbird 1.0.6-1.1.fc4 (X11/20050720) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 required=5 tests=[none] X-Spam-Level: X-Archive-Number: 200508/203 X-Sequence-Number: 13772 Hi, I have the following requirement for blobs: - use of standard JDBC API (not the LargeObject API); - blobs can be potentially huge in size; - the blob length is not known ahead of time; I have tried many things and decided to use oid instead of bytea (I got many OutOfMemoryExceptions with bytea). To push the data into the db it seems to just work fine with the JDBC API. But to pull the data from the db, I need to provide a custom Blob implementation. At least that what I have understood. To test the solution I have done the following custom Blob implementation. ... public class BlobImpl implements Blob { private final int limit = 10; // Change this value for testing private int cur = 0; public long length() throws SQLException { return Integer.MAX_VALUE; } public InputStream getBinaryStream() throws SQLException { return new InputStream() { @Override public int read() throws IOException { return cur++ < limit ? 'a' : -1; }}; } // All other methods throw an Exception ... } And the code that uses the Blob implementation (no postgresql specific code). ... insertStmt.setBlob(1, new BlobImpl()); insertStmt.executeUpdate(); conn.commit(); ... It seems to works fine. If I retrieve the inserted Blob from the database it's length is the value of the limit field not the length() value. So it seems I can use this kind of workaround to insert unknown length data in the db. The driver seems to ignore the length() value when inserting the data with the getBinaryStream(). Am I correct? If so it would be great. I will only use the custom Blob implement for insertions and updates. But are they some potential problem if I use this kind of implementation the way I describe it? Thanks Oscar