Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id A0479633353 for ; Sat, 13 Feb 2010 07:49:07 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 53396-08 for ; Sat, 13 Feb 2010 11:48:50 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from web35301.mail.mud.yahoo.com (web35301.mail.mud.yahoo.com [66.163.179.95]) by mail.postgresql.org (Postfix) with SMTP id C4B20633246 for ; Sat, 13 Feb 2010 07:48:56 -0400 (AST) Received: (qmail 59856 invoked by uid 60001); 13 Feb 2010 11:48:55 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1266061735; bh=dg7/Gkdw0wBw7v8MJTjnZOlfdjLqJxnso0ZhvQND+rY=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=yn8DH5Nn+RKyT1ahURv5byNJaeC6NEoIrvUjreIYTnhIKv7ymcKUZwF3yZN9FGVMxoHIAdJ7oimJ9PXE4NsWSEP6hLbWp+eLDQY1Og0MbjM8JFcATDCkfRoDebHoWB8xsAb3WLQsiBVakPS+5V8Tuv4U1O12IpJ6UIqYXST7/a8= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=EMEGEJpkGw/U/p56jWEy9h71iw7avoVWK0llgkhr4//hb4oTGQmr1EiNQTiZQVQ6GaHUoaGBUothsyZCk4wQz9an/4wS5DlUMnWdA9TIoXtpf5HdwHRTAkIuY5UemiL09JB6QC1LtQG8ItI1UqdSN+yBeub4K1dA2Xk0SQGLxY4=; Message-ID: <111275.59136.qm@web35301.mail.mud.yahoo.com> X-YMail-OSG: LxZIcLcVM1lXgZJKmMbzO3y2fcaJ9ztvsSiDZx.QJkD5oZQtc_fc.vB4rYFxj3XnudOa.U0SFulfEIK8O4J1QSOZ3S.noAJvtiLuh5heceUF2EwqBlhmhPEASXQCzVaBNCrTB_Lv2wgSax8sRhhYSHoLUU9Y9qAOsAH9r.3I1NhHIuuCuWbEmvftkrTkTUxfxpn3daYv1YtquiV9fm8KYdXTLn3I27sZxPbaa9eVFzXibsx8Bj1IQ3ZlDr7EXoMKeY3CQVi1pzpVGTOSIJ8VX1J7hDa.zXEHB_.3pCPS1_BQI8rMm.817sdLlz9YsepJRjurSY3.0GLmICJSvUKSt2CWT80jGGWieubAJdPVFcTTg30ES2lh9zblq36FYiQRxrh_XpFWq3Yhys_PINqD2JhtIittj6xbwDf7 Received: from [193.92.116.26] by web35301.mail.mud.yahoo.com via HTTP; Sat, 13 Feb 2010 03:48:55 PST X-Mailer: YahooMailClassic/9.1.10 YahooMailWebService/0.8.100.260964 Date: Sat, 13 Feb 2010 03:48:55 -0800 (PST) From: Gregory Kotsaftis Subject: Possible bug with BYTEA and JDBC To: pgsql-jdbc@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=-10 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 201002/19 X-Sequence-Number: 20306 (ALSO POSTED AT pgsql-bugs@postgresql.org)=0A------------------------------= ------------=0A=0AHi, =0A=0AI am using:=0A=0AWindows XP Pro SP3 EN=0AJDK 1.= 6.0_u18=0Apostgresql-8.4-701.jdbc4.jar=0Apostgresql-8.5alpha3=0A=0AI follow= ed the steps in the blob tutorial and tried to test the BYTEA example:=0Aht= tp://jdbc.postgresql.org/documentation/head/binary-data.html#binary-data-ex= ample=0AI found out that the BYTEA data that is persisted in the db is corr= upt. This is the details:=0A=0ACREATE TABLE PERSON (=0A=A0 =A0 PERSON_ID=A0= =A0 INTEGER=A0 =A0 =A0 =A0 PRIMARY KEY,=0A=A0 =A0 LASTNAME=A0 =A0=A0=A0VAR= CHAR(32)=A0 =A0 NOT NULL,=0A=A0 =A0 FIRSTNAME=A0 =A0 VARCHAR(32)=A0 =A0 NOT= NULL,=0A=A0 =A0 FACE=A0 =A0 =A0 =A0=A0=A0BYTEA=0A);=0AINSERT INTO PERSON(P= ERSON_ID,LASTNAME,FIRSTNAME,FACE)=0AVALUES(1,'KOTSAFTIS','GREGORY',NULL);= =0A=0A=0Apublic byte[] readBinaryFile(File f)=0A=A0 =A0 throws IOException= =0A{=0A=A0 =A0 byte[] bytes =3D null;=0A=A0 =A0 FileInputStream fin =3D new= FileInputStream(f);=0A=A0 =A0 try=0A=A0 =A0 {=0A=A0 =A0 =A0 =A0 long lengt= h =3D f.length();=0A=A0 =A0 =A0 =A0 if( length > Integer.MAX_VALUE )=0A=A0 = =A0 =A0 =A0 {=0A=A0 =A0 =A0 =A0 =A0 =A0 throw new IOException("File is too = large: " +=0A=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 f.getAbsolutePath());=0A=A0 = =A0 =A0 =A0 }=0A=0A=A0 =A0 =A0 =A0 bytes =3D new byte[(int)length];=0A=A0 = =A0 =A0 =A0 int numBytes =3D fin.read(bytes);=0A=A0 =A0 =A0 =A0 if( numByte= s!=3D length )=0A=A0 =A0 =A0 =A0 {=0A=A0 =A0 =A0 =A0 =A0 =A0 throw new IOEx= ception("Could not completely read file: " +=0A=A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 f.getAbsolutePath());=0A=A0 =A0 =A0 =A0 }=0A=A0 =A0 }=0A=A0 =A0 finally= =0A=A0 =A0 {=0A=A0 =A0 =A0 =A0 fin.close();=0A=A0 =A0 }=0A=0A=A0 =A0 return= ( bytes );=0A}=0A=0A=0Apublic void saveBinaryFile(byte[] bytes, File f)=0A= =A0 =A0 throws IOException=0A{=0A=A0 =A0 FileOutputStream fout =3D new File= OutputStream(f);=0A=A0 =A0 try=0A=A0 =A0 {=0A=A0 =A0 =A0 =A0 fout.write(byt= es);=0A=A0 =A0 }=0A=A0 =A0 finally=0A=A0 =A0 {=0A=A0 =A0 =A0 =A0 fout.close= ();=0A=A0 =A0 }=0A}=0A=0A=0A// STEP 1: change a person's face photo=0AConne= ction con =3D getConnection();=0APreparedStatement ps =3D con.prepareStatem= ent("UPDATE PERSON SET FACE=3D? WHERE PERSON_ID=3D?");=0Aps.setBytes(1, rea= dBinaryFile(new File("c:/1.jpg")));=0Aps.setInt(2, 1);=0Aps.executeUpdate()= ;=0Aps.close();=0Acon.close();=0A=0A// STEP 2: export person's face photo= =0AConnection con =3D Globals.DBMANAGER.getConnection();=0APreparedStatemen= t ps =3D con.prepareStatement("SELECT FACE FROM PERSON WHERE PERSON_ID=3D?"= );=0Aps.setInt(1, 1);=0AResultSet rs =3D ps.executeQuery();=0Ars.next();=0A= saveBinaryFile(rs.getBytes(1), new File("c:/2.jpg"));=0Ars.close();=0Aps.cl= ose();=0Acon.close();=0A=0AAfter executing the STEP 1, the data in the BYTE= A field is completely different than the original. I used "EMS SQL Manager = for PostgreSQL" to verify this.=0A=0AAfter executing STEP 2, the output fil= e is also corrupt. I used a hex-editor to verify this.=0A=0AWhen using "EMS= SQL Manager for PostgreSQL" to enter the BYTEA field from a source photo f= ile, the bytes match (hex-editor for the source file and EMS hex-edit on th= e db).=0A=0ACan anyone verify this, as I am new this BYTEA/BLOB issue. Am I= doing something wrong or is there some JDBC driver corruption issue?=0A=0A= Regards=0AGreg--=0A=0A=0A=0A=0A