pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mikael <mikael-aronsson@telia.com>
To: alkampfer <kazucat@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: bytea problem
Date: Tue, 22 Nov 2011 18:54:00 +0100
Message-ID: <C0D3A9F601FC450E8618CAB7327C7925@emea.itt.net> (raw)
References: <1321983450992-5014176.post@n5.nabble.com>

Is this a typo or is the code like this ?

            ps.setBytes(2,bytes);
            ps.setString(2,id);


----- Original Message ----- 
From: "alkampfer" <kazucat@gmail.com>
To: <pgsql-jdbc@postgresql.org>
Sent: Tuesday, November 22, 2011 6:37 PM
Subject: [JDBC] bytea problem


> Hello, this is my problem :
> I use java + postgres and I want to store image files into a table
>
> my table : (id int,  image bytea)
>
> the code :
>                byte bytes[] = new byte[(int)file.length()];
>
>                sqlq ="UPDATE table set image= ? where id=?";
>                ps = .....prepareStatement(sqlq);
>                ps.setBytes(2,bytes);
>                ps.setString(2,id);
>
> put the file into my table, stream of 41054 bytes, OK.
>
> but when I retrieve it from the database resultSet.getBytes("image") gives
> an array of 82108 bytes!!
> worst of all those bytes I get have no sense at all, like 00 00  00 or 11
> 11....
>
> thanks for the help!
>
>
>
>
> --
> View this message in context: 
> http://postgresql.1045698.n5.nabble.com/bytea-problem-tp5014176p5014176.html
> Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.
>
> -- 
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc 




view thread (9+ messages)  latest in thread

Message-ID: <C0D3A9F601FC450E8618CAB7327C7925@emea.itt.net>
Permalink:  ../C0D3A9F601FC450E8618CAB7327C7925@emea.itt.net/
Also on:    postgresql.org/message-id/C0D3A9F601FC450E8618CAB7327C7925@emea.itt.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: mikael-aronsson@telia.com, kazucat@gmail.com
  Subject: Re: bytea problem
  In-Reply-To: <C0D3A9F601FC450E8618CAB7327C7925@emea.itt.net>
  References: <1321983450992-5014176.post@n5.nabble.com> <C0D3A9F601FC450E8618CAB7327C7925@emea.itt.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