I am attaching a JDBC patch that is about to be applied for 7.2. 
Perhaps this fixes the problem because it deals with BLOBS.


> Hi Marc,
> 
> I seem to be having the same problem as you when trying to insert 
> audio files into the database. They are inserted OK using 
> PreparedStatement.setBinaryStream(), but the data is truncated
> when retrieved using PreparedStatement.getBinaryStream().
> This occurs using the jdbc7.1beta5 driver.
> 
> Interestingly, when I try to use an older JDBC driver (jdbc7.1beta4), it
> manages to correctly read back the object stored by the jdbc7.1beta5 driver.
> However, the jdbc7.1beta4 driver itself can't write the large object to the 
> database. It keeps throwing an exception:     InputStream as parameter not
> supported.
> 
> Can you let me know if you find out the cause of the problem, or
> better still a solution?
> 
> Thanks,
> Khanh Ho.
> 
> 
> > -----Original Message-----
> > From: The Hermit Hacker [mailto:[EMAIL PROTECTED]]
> > Sent: Sunday, 13 May 2001 2:45 AM
> > To: [EMAIL PROTECTED]
> > Cc: [EMAIL PROTECTED]
> > Subject: [JDBC] Displaying/Pulling Images using 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: [EMAIL PROTECTED]           secondary: 
> > scrappy@{freebsd|postgresql}.org
> > 
> > 
> > ---------------------------(end of 
> > broadcast)---------------------------
> > TIP 2: you can get off all lists at once with the unregister command
> >     (send "unregister YourEmailAddressHere" to 
> > [EMAIL PROTECTED])
> > 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
> 
> http://www.postgresql.org/users-lounge/docs/faq.html
> 

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  [EMAIL PROTECTED]               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
>From [EMAIL PROTECTED] Thu Feb 22 12:32:12 2001
Received: from mail.postgresql.org (webmail.postgresql.org [216.126.85.28])
        by candle.pha.pa.us (8.9.0/8.9.0) with ESMTP id NAA03990
        for <[EMAIL PROTECTED]>; Thu, 22 Feb 2001 13:32:11 -0500 (EST)
Received: from mail.postgresql.org (webmail.postgresql.org [216.126.85.28])
        by mail.postgresql.org (8.11.1/8.11.1) with SMTP id f1MITbx83134;
        Thu, 22 Feb 2001 13:29:37 -0500 (EST)
        (envelope-from [EMAIL PROTECTED])
Received: from lodge.guild.ab.ca (lodge.guild.ab.ca [209.91.118.66])
        by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f1MIPhx82902
        for <[EMAIL PROTECTED]>; Thu, 22 Feb 2001 13:25:43 -0500 (EST)
        (envelope-from [EMAIL PROTECTED])
Received: (from davidc@localhost)
        by lodge.guild.ab.ca (8.11.2/8.11.1) id f1MIPfM31699
        for [EMAIL PROTECTED]; Thu, 22 Feb 2001 11:25:41 -0700 (MST)
        (envelope-from davidc)
Date: Thu, 22 Feb 2001 11:25:41 -0700
From: Chad David <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Subject: [PATCHES] BlobInputStream.java patch
Message-ID: <[EMAIL PROTECTED]>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.2.5i
Precedence: bulk
Sender: [EMAIL PROTECTED]
Status: ORr

The current implementation of BlobInputStream does
not properly handle 8-bit unsigned data as it blindly
casts the byte to an int, which java most helpfully
promotes to a signed type.  This causes problems when
you can only return -1 to indicated EOF.

The following patch fixes the bug and has been tested
locally on image data.

Chad David
Guild Software Inc.
[EMAIL PROTECTED]


*** BlobInputStream.java    Thu Feb 22 11:11:23 2001
--- BlobInputStream.patched Thu Feb 22 11:10:38 2001
***************
*** 58,73 ****
     */
    public int read() throws java.io.IOException {
      try {
!       if(buffer==null || bpos>=buffer.length) {
          buffer=lo.read(bsize);
          bpos=0;
        }

        // Handle EOF
!       if(bpos>=buffer.length)
          return -1;

!       return (int) buffer[bpos++];
      } catch(SQLException se) {
        throw new IOException(se.toString());
      }
--- 58,81 ----
     */
    public int read() throws java.io.IOException {
      try {
!       if (buffer == null || bpos >= buffer.length) {
          buffer=lo.read(bsize);
          bpos=0;
        }

        // Handle EOF
!       if(bpos >= buffer.length) {
          return -1;
+       }

!       int ret = (buffer[bpos] & 0x7F);
!       if ((buffer[bpos] &0x80) == 0x80) {
!         ret |= 0x80;
!       }
!
!       bpos++;
!
!       return ret;
      } catch(SQLException se) {
        throw new IOException(se.toString());
      }
***************
*** 153,156 ****
    return true;
      }

! }
--- 161,164 ----
    return true;
      }

! }




---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html

Reply via email to