Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 1DE63632D01 for ; Thu, 5 Feb 2009 19:33:27 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 65058-08 for ; Thu, 5 Feb 2009 19:33:24 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from leary.csoft.net (leary.csoft.net [205.205.214.5]) by mail.postgresql.org (Postfix) with ESMTP id 58BF4632CF0 for ; Thu, 5 Feb 2009 19:33:24 -0400 (AST) Received: by leary.csoft.net (Postfix, from userid 1112) id 0F39CA1E5; Thu, 5 Feb 2009 18:33:22 -0500 (EST) Date: Thu, 5 Feb 2009 18:33:22 -0500 (EST) From: Kris Jurka X-X-Sender: books@leary.csoft.net To: David Wall cc: pgsql-jdbc Subject: Re: JDBC Blob helper class & streaming uploaded data into PG In-Reply-To: <4989EA02.5020703@computer.org> Message-ID: References: <4989EA02.5020703@computer.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200902/11 X-Sequence-Number: 19286 On Wed, 4 Feb 2009, David Wall wrote: > Does anybody have a JDBC Blob helper class so we can use the > setBlob()/getBlob() calls in JDBC for PG 8.3? It would be a class that > implements the java.sql.Blob interface. You really ought to use the driver's Blob implementation. Right now creating a new Blob isn't terribly straightforward. In theory the JDBC 4 method Connection.createBlob should be used, but that has not been implemented in the postgresql driver yet. The best way to do this at the moment is to insert a row with an empty blob, retrieve that blob and then write data into it. CREATE TABLE test (id int, bigdata oid); INSERT INTO test VALUES (1, lo_creat(-1)); ResultSet rs = stmt.executeQuery("SELECT bigdata FROM test WHERE id = 1"); rs.next(); Blob blob = rs.getBlob(1); OutputStream out = blob.setBinaryStream(1); // from java.util.zip. to compress the data. GZIPOutputStream gz = new GZIPOutputStream(out); while (!done) { gz.write(your data); } gz.close(); rs.close(); Kris Jurka