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

Displaying/Pulling Images using JDBC ...

From: The Hermit Hacker <scrappy(at)hub(dot)org>
To: <pgsql-jdbc(at)postgresql(dot)org>
Cc: <peter(at)retep(dot)org(dot)uk>
Subject: Displaying/Pulling Images using JDBC ...
Date: 2001-05-12 16:44:31
Message-ID: Pine.BSF.4.33.0105121344010.629-100000@mobile.hub.org (view raw or flat)
Thread:
Lists: pgsql-jdbc

Morning folks ...

	Been wracking our brains on this one for too long now ... have a
client that is trying to use JDBC to pull images stored in the database,
and, from what we can gather, the images are coming out 'truncated' ...

	If the client stores the images as ASCII (uuencoded) and pulls
those out, all works well, but if he stores them as binary/raw images, the
images don't come out ...

	If he retrieves that image using psql and stores it to a file,
that file is fine, so apparently the backend is storing it properly ...

	According to the table schema that we have, the image is being
stored as an 'oid' type ...

        In relation to the image settings, they are counting the bytes
that the stream is going to send to the client and verifying it on the
clients side, the numbers are not matching unless it is an ascii based
file....

	Both the backend server and the JDBC drivers are v7.1 ...

	Now, my thought on this is that it *sounds* like the JDBC is
hitting some sort of control character is the stream that tells it to stop
sending the image ... is this possible?  Some binary character that needs
to somehow be trapped?

	Image content is a mostly a faxed document saved as .tif format.
But it could be anything and we derive it from the file name.  We upload
the document to the database.  Please See the source

	Sample of the source they are using is as follows, is there something
that we are seeing:

PreparedStatement prepStmt = con.prepareStatement(selectstatement);
prepStmt.setString(1, medicalRecordId);
ResultSet rs = prepStmt.executeQuery();
if (rs.next()) {
  medicalRecordId = rs.getString(1);
  typeSOAP = rs.getString(2);
  code = rs.getString(3);
  String datetimetemp = rs.getString(4);
  datetime = Timestamp.valueOf(datetimetemp);
  testObject = rs.getString(5);
  testResult = rs.getString(6);
  note = rs.getString(7);
  appointmentId = rs.getString(8);
  patientId = rs.getString(9);
  test = rs.getString(10);
  category = rs.getString(11);

  //if(imageName == null){
  if(imageNametemp != null){
     imageName = rs.getString(12);


     BufferedInputStream bis = new BufferedInputStream(rs.getBinaryStream(13));
     System.out.println("value of bis"+bis.toString());
     //InputStream is = rs.getBinaryStream(13);

     //System.out.println("vale of inputstream"+is.toString());

     int TotLen=0;

     ByteArrayOutputStream imageOutputStream = new ByteArrayOutputStream(8164);

     byte[] b = new byte[8164];
     int len=0;

     try {
       while( (len = bis.read(b,0,8164)) != -1 ) {
         imageOutputStream.write(b,0,len);

         TotLen += len;
       }
       bis.close();
       imageAsBytes = imageOutputStream.toByteArray();

       System.out.println("value of baoslenght"+imageAsBytes.length);
       System.out.println("value of totlenght"+TotLen);

       System.out.println("vale of baos"+imageOutputStream.toString());
     }
     catch(IOException e) {
     }
  }
    prepStmt.close();


Marc G. Fournier                   ICQ#7615664               IRC Nick: Scrappy
Systems Administrator @ hub.org
primary: scrappy(at)hub(dot)org           secondary: scrappy(at){freebsd|postgresql}.org


Responses

pgsql-jdbc by date

Next:From: Tom LaneDate: 2001-05-12 18:21:17
Subject: Re: Displaying/Pulling Images using JDBC ...
Previous:From: BhuvaneswariDate: 2001-05-12 08:26:05
Subject: Error Retrieving Date Fields from tables

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