Skip site navigation (1) Skip section navigation (2)

Re: BLOB help - yes I've read around!

From: Brad Milne <mail_4brad(at)yahoo(dot)co(dot)uk>
To: pgsql-jdbc(at)postgresql(dot)org
Cc: Thomas Kellerer <spam_eater(at)gmx(dot)net>, Achilleas Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
Subject: Re: BLOB help - yes I've read around!
Date: 2009-04-07 21:34:20
Message-ID: 49DBC6DC.5030609@yahoo.co.uk (view raw or flat)
Thread:
Lists: pgsql-jdbc
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
>
>


In response to

Responses

pgsql-jdbc by date

Next:From: Thomas KellererDate: 2009-04-07 21:41:53
Subject: Re: BLOB help - yes I've read around!
Previous:From: John ListerDate: 2009-04-07 21:03:09
Subject: Re: Array passing

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group