pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Brad Milne <mail_4brad@yahoo.co.uk>
To: pgsql-jdbc@postgresql.org
Cc: Thomas Kellerer <spam_eater@gmx.net>
Cc: Achilleas Mantzios <achill@matrix.gatewaynet.com>
Subject: Re: BLOB help - yes I've read around!
Date: Wed, 08 Apr 2009 09:34:20 +1200
Message-ID: <49DBC6DC.5030609@yahoo.co.uk> (raw)
In-Reply-To: <grfoia$t7m$1@ger.gmane.org>
References: <49DB559F.3030805@yahoo.co.uk>
	<200904071657.08065.achill@matrix.gatewaynet.com>
	<49DB5D63.5040103@yahoo.co.uk>
	<grfoia$t7m$1@ger.gmane.org>

Thanks to you both

This works for me Thomas. For completeness, here is the setter again 
with a couple of fixes:

stmt.setBinaryStream(2,in,in.available());

or optionally (if it is a file):

stmt.setBinaryStream(2,in,blobFile.length());



Thomas Kellerer wrote:
> Brad Milne, 07.04.2009 16:04:
>> So how do you save the bytea data? I get:
>> Method 
>> org.postgresql.jdbc4.Jdbc4PreparedStatement.setBinaryStream(int, 
>> InputStream) is not yet implemented
>>
>
> The following has been working for me since I think 8.1 (and the 
> corresponding JDBC driver):
>
> Statement stmt = con.prepareStatement(
>  "INSERT INTO blob_table (id, blob_col) VALUES (?,?)");
> stmt.setInt(1, 42);
>
> File blobFile = new File("my_picture.jpg");
> InputStream in = new FileInputStream(blobFile);
> stmt.setBinaryStream(2, r, (int)f.length());
> stmt.executeUpdate();
> con.commit();
>
> Thomas
>
>




view thread (10+ messages)  latest in thread

Message-ID: <49DBC6DC.5030609@yahoo.co.uk>
Permalink:  ../49DBC6DC.5030609@yahoo.co.uk/
Also on:    postgresql.org/message-id/49DBC6DC.5030609@yahoo.co.uk

 · 

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: mail_4brad@yahoo.co.uk, spam_eater@gmx.net, achill@matrix.gatewaynet.com
  Subject: Re: BLOB help - yes I've read around!
  In-Reply-To: <49DBC6DC.5030609@yahoo.co.uk>
  References: <49DB559F.3030805@yahoo.co.uk> <200904071657.08065.achill@matrix.gatewaynet.com> <49DB5D63.5040103@yahoo.co.uk> <grfoia$t7m$1@ger.gmane.org> <49DBC6DC.5030609@yahoo.co.uk>

* 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