X-Original-To: pgsql-jdbc@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id ED790475461 for ; Sun, 2 Mar 2003 07:55:39 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 99191-08 for ; Sun, 2 Mar 2003 07:55:38 -0500 (EST) Received: from smartcall.no (unknown [62.97.160.24]) by postgresql.org (Postfix) with SMTP id 37AAA475458 for ; Sun, 2 Mar 2003 07:55:38 -0500 (EST) Received: (qmail 21924 invoked from network); 2 Mar 2003 13:16:19 -0000 Received: from unknown (HELO frodo) (62.97.176.24) by 62.97.160.24 with SMTP; 2 Mar 2003 13:16:19 -0000 From: "Uwe Kubosch" To: Subject: binary data Date: Sun, 2 Mar 2003 13:52:19 +0100 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4920.2300 Importance: Normal Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by amavisd-new X-Archive-Number: 200303/9 X-Sequence-Number: 6550 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 =3D new FileInputStream("image.png"); statement =3D getConnection().prepareStatement("UPDATE tfile SET content= =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(); } 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 =3D "SELECT content FROM tfile WHERE id=3D4"; resultSet =3D null; try { boolean more; resultSet =3D executeTheQuery(query); more =3D resultSet.next(); if (more) { InputStream is; is =3D 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 "=E5" is replaced with "=C3=A5". 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 _________________________________________