pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Barry Lind <blind@xythos.com>
To: Uwe Kubosch <donv@crusaders.no>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: binary data
Date: Sun, 02 Mar 2003 19:35:25 -0800
Message-ID: <3E62CD7D.5000303@xythos.com> (raw)
In-Reply-To: <CHECLDNPGHELOIINBBLEKEEEEIAA.donv@crusaders.no>
References: <CHECLDNPGHELOIINBBLEKEEEEIAA.donv@crusaders.no>

Uwe,

Can you submit a test case that demonstrates the problem?  I use the 
bytea type in my apps without problems, so there must be something 
different about how you are doing this.

thanks,
--Barry


Uwe Kubosch wrote:
> Hi all!
> 
> I'm trying to store image data in a postgresql 7.3.2 data using the 7.3.2
> jdbc3 drivers.  The table "tfile" contains an integer field "id" and a bytea
> field "content".
> 
> I store the image with code similar to this:
> 
>   InputStream is;
>   PreparedStatement statement;
>   int rowsAffected;
> 
>   is = new FileInputStream("image.png");
>   statement = getConnection().prepareStatement("UPDATE tfile SET content=?
> WHERE id=4");
>   getConnection().setAutoCommit(false);
>   statement.setBinaryStream(1, is, MAX_FILE_SIZE);
>   rowsAffected = statement.executeUpdate();
>   getConnection().commit();
>   getConnection().setAutoCommit(true);
>   is.close();
> }
> 
> This works fine, and the size of the "content" field in the database is
> equal to the size of the file, 4342 bytes.
> 
> I fetch the image back from the database with code similar to this:
> 
> String query;
> ResultSet resultSet;
> 
> query = "SELECT content FROM tfile WHERE id=4";
> resultSet = null;
> 
> try {
>   boolean more;
> 
>   resultSet = executeTheQuery(query);
>   more = resultSet.next();
> 
>   if (more) {
>     InputStream is;
> 
>     is = resultSet.getBinaryStream("content");
>     setContent(is);
>   }
> } catch (SQLException anSQLException) {
> }
> 
> I've read and re-read the documentation, and this should work.  However,
> checking the size of the content InputStream shows that the size is 5527
> bytes instead of 4342.  Doing a compare with the original image reveals what
> seems like unicode character sequences.  For example "å" is replaced with
> "Ã¥".
> 
> Is this correct behaviour?  Must I convert binary data from a bytea field?
> 
> If I have missed something obvious, I apologize, but I hope someone can help
> me, please.  Any help is greatly appreciated.
> 
> 
> With kind regards,
> Uwe Kubosch
> 
> _________________________________________
> Uwe Kubosch
> Adviser eCommerce
> ICQ#: 71437007
> More ways to contact me: http://wwp.icq.com/71437007
> _________________________________________
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
> 





view thread (15+ messages)  latest in thread

Message-ID: <3E62CD7D.5000303@xythos.com>
Permalink:  ../3E62CD7D.5000303@xythos.com/
Also on:    postgresql.org/message-id/3E62CD7D.5000303@xythos.com

 · 

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: blind@xythos.com, donv@crusaders.no
  Subject: Re: binary data
  In-Reply-To: <3E62CD7D.5000303@xythos.com>
  References: <CHECLDNPGHELOIINBBLEKEEEEIAA.donv@crusaders.no> <3E62CD7D.5000303@xythos.com>

* 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