X-Original-To: pgsql-jdbc@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id DD3844758DC for ; Sun, 2 Mar 2003 22:35:54 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 09636-06 for ; Sun, 2 Mar 2003 22:35:22 -0500 (EST) Received: from mail.xythos.com (unknown [206.14.210.116]) by postgresql.org (Postfix) with ESMTP id C3523475A3F for ; Sun, 2 Mar 2003 22:35:22 -0500 (EST) Received: from ravms by mail.xythos.com with mail-ok (Exim 3.36 #3) id 18pgk7-0000JS-00; Mon, 03 Mar 2003 03:35:55 +0000 Received: from h-66-166-17-184.snvacaid.covad.net ([66.166.17.184] helo=xythos.com) by mail.xythos.com with asmtp (Exim 3.36 #3) id 18pgk6-0000JH-00; Mon, 03 Mar 2003 03:35:55 +0000 Message-ID: <3E62CD7D.5000303@xythos.com> Date: Sun, 02 Mar 2003 19:35:25 -0800 From: Barry Lind User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021130 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Uwe Kubosch Cc: pgsql-jdbc@postgresql.org Subject: Re: binary data References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed X-Envelope-To: donv@crusaders.no, pgsql-jdbc@postgresql.org Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by amavisd-new X-Archive-Number: 200303/23 X-Sequence-Number: 6564 Uwe, Can you submit a test case that demonstrates the problem? I use the=20 bytea type in my apps without problems, so there must be something=20 different about how you are doing this. thanks, --Barry Uwe Kubosch wrote: > Hi all! >=20 > 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 by= tea > field "content". >=20 > I store the image with code similar to this: >=20 > InputStream is; > PreparedStatement statement; > int rowsAffected; >=20 > is =3D new FileInputStream("image.png"); > statement =3D getConnection().prepareStatement("UPDATE tfile SET conten= t=3D? > WHERE id=3D4"); > getConnection().setAutoCommit(false); > statement.setBinaryStream(1, is, MAX_FILE_SIZE); > rowsAffected =3D statement.executeUpdate(); > getConnection().commit(); > getConnection().setAutoCommit(true); > is.close(); > } >=20 > This works fine, and the size of the "content" field in the database is > equal to the size of the file, 4342 bytes. >=20 > I fetch the image back from the database with code similar to this: >=20 > String query; > ResultSet resultSet; >=20 > query =3D "SELECT content FROM tfile WHERE id=3D4"; > resultSet =3D null; >=20 > try { > boolean more; >=20 > resultSet =3D executeTheQuery(query); > more =3D resultSet.next(); >=20 > if (more) { > InputStream is; >=20 > is =3D resultSet.getBinaryStream("content"); > setContent(is); > } > } catch (SQLException anSQLException) { > } >=20 > 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 w= hat > seems like unicode character sequences. For example "=E5" is replaced wi= th > "=C3=A5". >=20 > Is this correct behaviour? Must I convert binary data from a bytea field? >=20 > If I have missed something obvious, I apologize, but I hope someone can h= elp > me, please. Any help is greatly appreciated. >=20 >=20 > With kind regards, > Uwe Kubosch >=20 > _________________________________________ > Uwe Kubosch > Adviser eCommerce > ICQ#: 71437007 > More ways to contact me: http://wwp.icq.com/71437007 > _________________________________________ >=20 >=20 > ---------------------------(end of broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org >=20