Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id D4E5A632319 for ; Sat, 13 Feb 2010 07:41:38 -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 52263-05 for ; Sat, 13 Feb 2010 11:41:21 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from web35304.mail.mud.yahoo.com (web35304.mail.mud.yahoo.com [66.163.179.98]) by mail.postgresql.org (Postfix) with SMTP id 7E6956326D5 for ; Sat, 13 Feb 2010 07:41:27 -0400 (AST) Received: (qmail 69344 invoked by uid 60001); 13 Feb 2010 11:41:25 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1266061285; bh=0lKX/m6mkasMfvCsks+ePDgCwbtwNczoM7gbBg0se8g=; h=Message-ID:X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type; b=g1t88Mmcaqpiz0QH2vWnW7j5LxOWAjPZ+qmOluQjI58wEeeHPOwu35cZ+E2JCtH+z6ODwzzauVnon5exuPXPdGCxvlmSmFd7oSGtQfjhFUvPWC24LAUhLlR8p3SQxPptTdZwezMlrPoRlOaXfc9FCwgx44abL5cArkCnWXONges= 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; b=nKtVKWYZ5RGKPP4yvoqd1Jyv1mg6MI7S6UWcwPyDSVUGn5XO6JV8dlRD29PHPuE3t4nH21/WoLfAHzlD8zGnTsS4KcRnbIno7APiZVZo1MIM3sOn9FMDQmsoN2D2Ch3GfobpOKrl7wUI3Cjo9ID/vDZ5VagsrGv9DUxPox2l6wQ=; Message-ID: <245984.68614.qm@web35304.mail.mud.yahoo.com> X-YMail-OSG: FZLDCvIVM1n2SORh2n4j09_V8YIMmTdXlpZ5ZkfclDjYd0jUeQsQ0g4KayWwQEpnlSsdH7wTuqCg.6RuIyL12_X7_DP_wup7ZN8C9yENEkYYMkdruLtbetnf5TJ9POXmdo1OnaNx6fYwi6lcUeprHzVp0WC6KfPlhT6qifGuZCNsVXqv6T3Fx9IQgNpjR04EmGrKzALYFPtuCw9ouLfZbRiJBkPyCoKR7QiGCGnf_P5XS9KFQp0DunAS25.WtKS91.m2SniN3hAckKEsL9nzPNccxRcf_y1AB93LmfzFEKesvPUcwJwBLJOpHfPj_hJZI8Gy8rvvdaxEF7yTyUpTZmr9oW7GKDbsJoYJbPae7djafnjwILDh0QxUg.LRHpzXA7PncWK43PmNTlE- Received: from [193.92.116.26] by web35304.mail.mud.yahoo.com via HTTP; Sat, 13 Feb 2010 03:41:25 PST X-Mailer: YahooMailClassic/9.1.10 YahooMailWebService/0.8.100.260964 Date: Sat, 13 Feb 2010 03:41:25 -0800 (PST) From: Gregory Kotsaftis Subject: Possible bug with BYTEA and JDBC To: pgsql-bugs@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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/133 X-Sequence-Number: 25919 Hi, I am using: Windows XP Pro SP3 EN JDK 1.6.0_u18 postgresql-8.4-701.jdbc4.jar postgresql-8.5alpha3 I followed the steps in the blob tutorial and tried to test the BYTEA example: http://jdbc.postgresql.org/documentation/head/binary-data.html#binary-data-example I found out that the BYTEA data that is persisted in the db is corrupt. This is the details: CREATE TABLE PERSON ( PERSON_ID INTEGER PRIMARY KEY, LASTNAME VARCHAR(32) NOT NULL, FIRSTNAME VARCHAR(32) NOT NULL, FACE BYTEA ); INSERT INTO PERSON(PERSON_ID,LASTNAME,FIRSTNAME,FACE) VALUES(1,'KOTSAFTIS','GREGORY',NULL); public byte[] readBinaryFile(File f) throws IOException { byte[] bytes = null; FileInputStream fin = new FileInputStream(f); try { long length = f.length(); if( length > Integer.MAX_VALUE ) { throw new IOException("File is too large: " + f.getAbsolutePath()); } bytes = new byte[(int)length]; int numBytes = fin.read(bytes); if( numBytes!= length ) { throw new IOException("Could not completely read file: " + f.getAbsolutePath()); } } finally { fin.close(); } return( bytes ); } public void saveBinaryFile(byte[] bytes, File f) throws IOException { FileOutputStream fout = new FileOutputStream(f); try { fout.write(bytes); } finally { fout.close(); } } // STEP 1: change a person's face photo Connection con = getConnection(); PreparedStatement ps = con.prepareStatement("UPDATE PERSON SET FACE=? WHERE PERSON_ID=?"); ps.setBytes(1, readBinaryFile(new File("c:/1.jpg"))); ps.setInt(2, 1); ps.executeUpdate(); ps.close(); con.close(); // STEP 2: export person's face photo Connection con = Globals.DBMANAGER.getConnection(); PreparedStatement ps = con.prepareStatement("SELECT FACE FROM PERSON WHERE PERSON_ID=?"); ps.setInt(1, 1); ResultSet rs = ps.executeQuery(); rs.next(); saveBinaryFile(rs.getBytes(1), new File("c:/2.jpg")); rs.close(); ps.close(); con.close(); After executing the STEP 1, the data in the BYTEA field is completely different than the original. I used "EMS SQL Manager for PostgreSQL" to verify this. After executing STEP 2, the output file is also corrupt. I used a hex-editor to verify this. When using "EMS SQL Manager for PostgreSQL" to enter the BYTEA field from a source photo file, the bytes match (hex-editor for the source file and EMS hex-edit on the db). Can anyone verify this, as I am new this BYTEA/BLOB issue. Am I doing something wrong or is there some JDBC driver corruption issue? Regards Greg--