pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Kris Jurka <books@ejurka.com>
To: David Wall <d.wall@computer.org>
Cc: pgsql-jdbc <pgsql-jdbc@postgresql.org>
Subject: Re: JDBC Blob helper class & streaming uploaded data into PG
Date: Thu, 5 Feb 2009 18:33:22 -0500 (EST)
Message-ID: <Pine.BSO.4.64.0902051821080.17892@leary.csoft.net> (raw)
In-Reply-To: <4989EA02.5020703@computer.org>
References: <4989EA02.5020703@computer.org>



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



view thread (3+ messages)  latest in thread

Message-ID: <Pine.BSO.4.64.0902051821080.17892@leary.csoft.net>
Permalink:  ../Pine.BSO.4.64.0902051821080.17892@leary.csoft.net/
Also on:    postgresql.org/message-id/Pine.BSO.4.64.0902051821080.17892@leary.csoft.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: books@ejurka.com, d.wall@computer.org
  Subject: Re: JDBC Blob helper class & streaming uploaded data into PG
  In-Reply-To: <Pine.BSO.4.64.0902051821080.17892@leary.csoft.net>
  References: <4989EA02.5020703@computer.org> <Pine.BSO.4.64.0902051821080.17892@leary.csoft.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox