title: What has changed between postgres jdbc 8.4 and 9 regarding bytearrays?
body: <p>I'm running Mac OSX 10.6 with PostgreSQL 9.0. I wrote a simple Java application that insert an image in a bytea field and then query the same field to check it.</p>
  
  <p>The table:</p>
  
  <pre><code> CREATE TABLE test.test_table
     (
     id integer NOT NULL,
    image bytea,
    CONSTRAINT test_table_pkey PRIMARY KEY (id)
  );
  </code></pre>
  
  <p>The program is something like:</p>
  
  <pre><code>//insert the file
      PreparedStatement ps = connection.prepareStatement("INSERT INTO test.test_table( id, image ) VALUES (?, ?);");
              byte[] bytesFromFile = readFile("img/test1.bmp");
              ps.setInt(1, 1);
              ps.setBytes(2, bytesFromFile);
              ps.execute();
              ps.close();
  
              PreparedStatement stmt = connection.prepareStatement("Select id,image from test.test_table");
              ResultSet rs = stmt.executeQuery();
      //Get the file from the BD  and save it to the FS 
              while (rs.next()) {
                  String id = rs.getString(1);
                  InputStream imageStream = rs.getBinaryStream(2);
                  String imageName = OUTPUT_DIR + "/" + id + ".bmp";
                  FileOutputStream f = new FileOutputStream(imageName);
                  byte buff[] = new byte[1024];
                  int l;
                  while ((l = imageStream.read(buff)) &gt; 0) {
                      f.write(buff, 0, l);
                  }
                  f.close();
                  System.out.println("CREATED : " + imageName);// + " size " +
  
              }
  </code></pre>
  
  <p>Here are the facts.</p>
  
  <ol>
  <li><p>Using the driver
  postgresql-9.0-801.jdbc4.jar it
  works perfectly both in
  PostgreSQL 8.4 and with PostgreSQL 9</p></li>
  <li><p>Using the driver 8.4-701.jdbc4 works
  only in PostgreSQL 8.4 .</p></li>
  <li>Using the
  driver 8.4-701.jdbc4 with PostgreSQL
  9 doesn't work. The extracted file is different. An md5 shows that the content in the database is equals to the original file. Therefore, my assumption is that the problem is during the extraction of the file.</li>
  </ol>
  
  <p>I can upgrade the driver, thats no problem. My concern is: what has changed inside the communication protocol that is no longer supported in PostgreSQL 9 ?</p>