Skip site navigation (1) Skip section navigation (2)

Re: [INTERFACES] Trouble with large objets and jdbc

From: Brian P Millett <bpm(at)ec-group(dot)com>
To: Henri-Pierre CHARLES <hpc(at)prism(dot)uvsq(dot)fr>
Cc: pgsql-interfaces(at)hub(dot)org
Subject: Re: [INTERFACES] Trouble with large objets and jdbc
Date: 1999-05-13 15:26:51
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-interfaces
Henri-Pierre CHARLES wrote:

> Hello,
> I want to use large objets to store images in a database with the jdbc
> interface. I have try to use PreparedStatement which has
> setBinaryStream () but it's not possible with the old version I
> usually use (6.4.2). I have download the 6.5b1 and unfortunately
> setBinaryStream () is still not implemented.

This bug has been fixed as of Monday.  They (Hackers group) have also fixed a big hairy bug with the backend.  If you use the anonymous cvs to checkout the latest snapshot, you will
find an example that works, the works also.

I also use code such as this to work fine:

  // The UPDATE statement to be used for populating the item_picture and
  // item_descr columns
  String itemUpdateStmt = "UPDATE item SET item_picture = ?, item_descr = ?"+
   " WHERE item_num = ?";
   // Create a PreparedStatement object & use it to update the item_picture
   // and item_descr columns in the item table
   PreparedStatement updateStmt = conn.prepareStatement(itemUpdateStmt);
    // File names for the image & text files
    String itemPictureFileName = ("item_" + new Integer(i).toString()
             + ".gif");
    String itemDescrFileName = ("item_" + new Integer(i).toString()
           + ".txt");

    // objects corresponding to the image & text files
    File itemPictureFile = new File(itemPictureFileName);
    File itemDescrFile = new File(itemDescrFileName);

    // Byte arrays to store text & byte data for the item_picture and
    // item_descr columns
    byte itemPictureArray [] = new byte[(int)itemPictureFile.length()];
    String itemDescrString = "";

    // Using to reading the image & text files
    // into byte arrays
    FileInputStream itemPictureInputStream = new
     FileInputStream(itemPictureFile);, 0,

    FileReader fr = new FileReader(itemDescrFile);
    BufferedReader br = new BufferedReader(fr);
    String lineIn;
    while ((lineIn = br.readLine()) != null)
     itemDescrString += lineIn;

    // Set the values of the parameters & execute the statement
    updateStmt.setBytes(1, itemPictureArray);
    updateStmt.setString(2, itemDescrString);
    updateStmt.setInt(3, i);

Then to read/view the image, I do:

     // read the image from the resultset
     byte itemPictureArray [] = queryResults.getBytes(2);
      Image img = Toolkit.getDefaultToolkit().createImage(itemPictureArray);

Brian Millett
Enterprise Consulting Group     "Heaven can not exist,
(314) 205-9030                     If the family is not eternal"
bpm(at)ec-group(dot)com                   F. Ballard Washburn

In response to

pgsql-interfaces by date

Next:From: Peter HarveyDate: 1999-05-13 15:32:07
Subject: Re: [INTERFACES] ODBC Driver updated
Previous:From: Byron NikolaidisDate: 1999-05-13 15:24:15
Subject: Re: [INTERFACES] ODBC Driver updated

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group