Thread: Displaying/Pulling Images using JDBC ...

Displaying/Pulling Images using JDBC ...

From
The Hermit Hacker
Date:

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@hub.org           secondary: scrappy@{freebsd|postgresql}.org


Re: Displaying/Pulling Images using JDBC ...

From
Tom Lane
Date:
The Hermit Hacker <scrappy@hub.org> writes:
>     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?

Embedded nulls would be the likely cause of trouble.

If you're seeing OIDs in the database then the actual storage is
presumably in large objects.  lo_read and friends are null-safe as far
as I know; probably the problem is somewhere inside the JDBC driver.

            regards, tom lane

Re: Displaying/Pulling Images using JDBC ...

From
The Hermit Hacker
Date:
On Sat, 12 May 2001, Tom Lane wrote:

> The Hermit Hacker <scrappy@hub.org> writes:
> >     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?
>
> Embedded nulls would be the likely cause of trouble.
>
> If you're seeing OIDs in the database then the actual storage is
> presumably in large objects.  lo_read and friends are null-safe as far
> as I know; probably the problem is somewhere inside the JDBC driver.

that's kinda what I'm figuring too ... the question is where, and is there
a suitable work around ;(



Re: Displaying/Pulling Images using JDBC ...

From
"Dave Cramer"
Date:
----- Original Message -----
From: "The Hermit Hacker" <scrappy@hub.org>
To: "Tom Lane" <tgl@sss.pgh.pa.us>
Cc: <pgsql-jdbc@postgresql.org>; <peter@retep.org.uk>
Sent: Saturday, May 12, 2001 2:55 PM
Subject: Re: [JDBC] Displaying/Pulling Images using JDBC ...


> On Sat, 12 May 2001, Tom Lane wrote:
>
> > The Hermit Hacker <scrappy@hub.org> writes:
> > > 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?
> >
> > Embedded nulls would be the likely cause of trouble.
> >
> > If you're seeing OIDs in the database then the actual storage is
> > presumably in large objects.  lo_read and friends are null-safe as far
> > as I know; probably the problem is somewhere inside the JDBC driver.
>
> that's kinda what I'm figuring too ... the question is where, and is there
> a suitable work around ;(
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>
>


Re: Displaying/Pulling Images using JDBC ...

From
"Dave Cramer"
Date:
 Sorry for the last post.. slip of the finger


Looking at the code; the work is done by PG_Stream, which reads from a
BufferedInputStream into an array until it is done.

I don't really see where it would run into problems.

Can you send me one of the troublesome images.

--dc--
----- Original Message -----
From: "The Hermit Hacker" <scrappy@hub.org>
To: "Tom Lane" <tgl@sss.pgh.pa.us>
Cc: <pgsql-jdbc@postgresql.org>; <peter@retep.org.uk>
Sent: Saturday, May 12, 2001 2:55 PM
Subject: Re: [JDBC] Displaying/Pulling Images using JDBC ...


> On Sat, 12 May 2001, Tom Lane wrote:
>
> > The Hermit Hacker <scrappy@hub.org> writes:
> > > 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?
> >
> > Embedded nulls would be the likely cause of trouble.
> >
> > If you're seeing OIDs in the database then the actual storage is
> > presumably in large objects.  lo_read and friends are null-safe as far
> > as I know; probably the problem is somewhere inside the JDBC driver.
>
> that's kinda what I'm figuring too ... the question is where, and is there
> a suitable work around ;(
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>
>


RE: Displaying/Pulling Images using JDBC ...

From
Joe Shevland
Date:
Hi Marc,

I'm not sure if you've had a successful solution worked out by now, but our
web application frequently stores and retrieves images (GIF and JPEG at this
stage) using the 7.1 (RC 4 or 5 I think) code and I haven't encountered a
problem yet. Another application stores all manner of binary files (anything
the user throws at it, PDF/Word/etc) and again, we haven't seen a problem.

Some notes on the code:

i) I use the setAutoCommit(false) method of the Connection class for all
large object dealings (select/insert/update) as this seems to be required
(ensures commits don't occur after each statement or whatever).

ii) I've tended to use setBytes() instead of setBinaryStream() in the
PreparedStatement object. Unsure if this matters, but I usally get passed an
array of bytes from the image uploading code. Streams may be more efficient
but I'm not sure if this is where the bug lies, if indeed it is a bug.

Also, if you want to try out uploading/downloading the offending image I can
give you an account on our 'WebFormX' product site to see if its works
against Postgres, basically builds online forms and you can upload form
logos/backgrounds as well as image fields.

Cheers,
Joe

> -----Original Message-----
> From: The Hermit Hacker [mailto:scrappy@hub.org]
> Sent: Sunday, 13 May 2001 2:45 AM
> To: pgsql-jdbc@postgresql.org
> Cc: peter@retep.org.uk
> 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: scrappy@hub.org           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
> majordomo@postgresql.org)
>

RE: Displaying/Pulling Images using JDBC ...

From
"Ho, Khanh"
Date:
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:scrappy@hub.org]
> Sent: Sunday, 13 May 2001 2:45 AM
> To: pgsql-jdbc@postgresql.org
> Cc: peter@retep.org.uk
> 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: scrappy@hub.org           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
> majordomo@postgresql.org)
>

Re: Displaying/Pulling Images using JDBC ...

From
Bruce Momjian
Date:
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:scrappy@hub.org]
> > Sent: Sunday, 13 May 2001 2:45 AM
> > To: pgsql-jdbc@postgresql.org
> > Cc: peter@retep.org.uk
> > 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: scrappy@hub.org           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
> > majordomo@postgresql.org)
> >
>
> ---------------------------(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
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Compiling JDBC Driver - impossible!

From
"Mike Cannon-Brookes"
Date:
Ok, I give up!

How do I compile the JDBC driver? I'm running into those dreaded
"InputStream as parameter not supported" errors with my current build, and
as below this appears to have been fixed.

So I've sucked down the latest source from CVS.

Now how do I compile JUST the JDBC driver?

I've tried
- "ant" in both the root and /src/interfaces/jdbc directory
- "./configure; ant" in both places
- playing with the build file to add major and minor properties myself

I still get errors about cannot compile {major}; etc.

Can someone _please_ document the JDBC build process ? (Or simplify it!)
IMHO (and I know we've had this argument before ;)) it should just be a
single 'ant' call in the right place, I see no reason this couldn't work.

-mike


Mike Cannon-Brookes - Founder, Core Developer
OpenSymphony - http://www.opensymphony.com
"The Open Source J2EE Component Project"

Latest News
- Cache in on faster, more reliable JSPs
http://www.javaworld.com/javaworld/jw-05-2001/jw-0504-cache.html



> -----Original Message-----
> From: pgsql-jdbc-owner@postgresql.org
> [mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Bruce Momjian
> Sent: Monday, May 14, 2001 11:13 AM
> To: Ho, Khanh
> Cc: The Hermit Hacker; pgsql-jdbc@postgresql.org
> Subject: Re: Displaying/Pulling Images using JDBC ...
>
>
>
> 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:scrappy@hub.org]
> > > Sent: Sunday, 13 May 2001 2:45 AM
> > > To: pgsql-jdbc@postgresql.org
> > > Cc: peter@retep.org.uk
> > > 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: scrappy@hub.org           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
> > > majordomo@postgresql.org)
> > >
> >
> > ---------------------------(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
>   pgman@candle.pha.pa.us               |  (610) 853-3000
>   +  If your life is a hard drive,     |  830 Blythe Avenue
>   +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
>


Re: Compiling JDBC Driver - impossible!

From
Bruce Momjian
Date:
I think you type 'gmake' in the jdbc directory.  That runs ant.

> Ok, I give up!
>
> How do I compile the JDBC driver? I'm running into those dreaded
> "InputStream as parameter not supported" errors with my current build, and
> as below this appears to have been fixed.
>
> So I've sucked down the latest source from CVS.
>
> Now how do I compile JUST the JDBC driver?
>
> I've tried
> - "ant" in both the root and /src/interfaces/jdbc directory
> - "./configure; ant" in both places
> - playing with the build file to add major and minor properties myself
>
> I still get errors about cannot compile {major}; etc.
>
> Can someone _please_ document the JDBC build process ? (Or simplify it!)
> IMHO (and I know we've had this argument before ;)) it should just be a
> single 'ant' call in the right place, I see no reason this couldn't work.
>
> -mike
>
>
> Mike Cannon-Brookes - Founder, Core Developer
> OpenSymphony - http://www.opensymphony.com
> "The Open Source J2EE Component Project"
>
> Latest News
> - Cache in on faster, more reliable JSPs
> http://www.javaworld.com/javaworld/jw-05-2001/jw-0504-cache.html
>
>
>
> > -----Original Message-----
> > From: pgsql-jdbc-owner@postgresql.org
> > [mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Bruce Momjian
> > Sent: Monday, May 14, 2001 11:13 AM
> > To: Ho, Khanh
> > Cc: The Hermit Hacker; pgsql-jdbc@postgresql.org
> > Subject: Re: Displaying/Pulling Images using JDBC ...
> >
> >
> >
> > 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:scrappy@hub.org]
> > > > Sent: Sunday, 13 May 2001 2:45 AM
> > > > To: pgsql-jdbc@postgresql.org
> > > > Cc: peter@retep.org.uk
> > > > 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: scrappy@hub.org           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
> > > > majordomo@postgresql.org)
> > > >
> > >
> > > ---------------------------(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
> >   pgman@candle.pha.pa.us               |  (610) 853-3000
> >   +  If your life is a hard drive,     |  830 Blythe Avenue
> >   +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
> >
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026

Re: Displaying/Pulling Images using JDBC ...

From
Tom Lane
Date:
Bruce Momjian <pgman@candle.pha.pa.us> writes:
> !       int ret = (buffer[bpos] & 0x7F);
> !       if ((buffer[bpos] &0x80) == 0x80) {
> !         ret |= 0x80;
> !       }

That seems like an awfully ugly (and slow) way of doing unsigned
promotion.

If Java doesn't have a notion of unsigned chars, perhaps this would do:

    return ((int) buffer[bpos++]) & 0xFF;

            regards, tom lane

RE: Compiling JDBC Driver - impossible!

From
"Mike Cannon-Brookes"
Date:
This didn't work. Reason? It tries to call "buildfile" instead of "ant".

I modified Makefile.global to set ANT=ant and it gave the same errors as
running ant myself.

Again, we have two build systems here. Not everyone has ant fixed to 'ant'
or 'buildfile', which makes automated builds hard.

Why can't we just use ant? I see no reason the functionality of the JDBC
Makefile can't be done purely in Ant.

-mike

Mike Cannon-Brookes - Founder, Core Developer
OpenSymphony - http://www.opensymphony.com
"The Open Source J2EE Component Project"

Latest News
- Cache in on faster, more reliable JSPs
http://www.javaworld.com/javaworld/jw-05-2001/jw-0504-cache.html



> -----Original Message-----
> From: Bruce Momjian [mailto:pgman@candle.pha.pa.us]
> Sent: Monday, May 14, 2001 11:36 AM
> To: Mike Cannon-Brookes
> Cc: pgsql-jdbc@postgresql.org
> Subject: Re: [JDBC] Compiling JDBC Driver - impossible!
>
>
>
> I think you type 'gmake' in the jdbc directory.  That runs ant.
>
> > Ok, I give up!
> >
> > How do I compile the JDBC driver? I'm running into those dreaded
> > "InputStream as parameter not supported" errors with my current
> build, and
> > as below this appears to have been fixed.
> >
> > So I've sucked down the latest source from CVS.
> >
> > Now how do I compile JUST the JDBC driver?
> >
> > I've tried
> > - "ant" in both the root and /src/interfaces/jdbc directory
> > - "./configure; ant" in both places
> > - playing with the build file to add major and minor properties myself
> >
> > I still get errors about cannot compile {major}; etc.
> >
> > Can someone _please_ document the JDBC build process ? (Or simplify it!)
> > IMHO (and I know we've had this argument before ;)) it should just be a
> > single 'ant' call in the right place, I see no reason this
> couldn't work.
> >
> > -mike
> >
> >
> > Mike Cannon-Brookes - Founder, Core Developer
> > OpenSymphony - http://www.opensymphony.com
> > "The Open Source J2EE Component Project"
> >
> > Latest News
> > - Cache in on faster, more reliable JSPs
> > http://www.javaworld.com/javaworld/jw-05-2001/jw-0504-cache.html
> >
> >
> >
> > > -----Original Message-----
> > > From: pgsql-jdbc-owner@postgresql.org
> > > [mailto:pgsql-jdbc-owner@postgresql.org]On Behalf Of Bruce Momjian
> > > Sent: Monday, May 14, 2001 11:13 AM
> > > To: Ho, Khanh
> > > Cc: The Hermit Hacker; pgsql-jdbc@postgresql.org
> > > Subject: Re: Displaying/Pulling Images using JDBC ...
> > >
> > >
> > >
> > > 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:scrappy@hub.org]
> > > > > Sent: Sunday, 13 May 2001 2:45 AM
> > > > > To: pgsql-jdbc@postgresql.org
> > > > > Cc: peter@retep.org.uk
> > > > > 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: scrappy@hub.org           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
> > > > > majordomo@postgresql.org)
> > > > >
> > > >
> > > > ---------------------------(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
> > >   pgman@candle.pha.pa.us               |  (610) 853-3000
> > >   +  If your life is a hard drive,     |  830 Blythe Avenue
> > >   +  Christ can be your backup.        |  Drexel Hill,
> Pennsylvania 19026
> > >
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
> >
>
> --
>   Bruce Momjian                        |  http://candle.pha.pa.us
>   pgman@candle.pha.pa.us               |  (610) 853-3000
>   +  If your life is a hard drive,     |  830 Blythe Avenue
>   +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026


...How to remove ?

From
"Subhramanya Shiva"
Date:
How to remove from this mailing list !!!!

regards
Shiva

> Hi Marc,
>
> I'm not sure if you've had a successful solution worked out by now, but
our
> web application frequently stores and retrieves images (GIF and JPEG at
this
> stage) using the 7.1 (RC 4 or 5 I think) code and I haven't encountered a
> problem yet. Another application stores all manner of binary files
(anything
> the user throws at it, PDF/Word/etc) and again, we haven't seen a problem.
>
> Some notes on the code:
>
> i) I use the setAutoCommit(false) method of the Connection class for all
> large object dealings (select/insert/update) as this seems to be required
> (ensures commits don't occur after each statement or whatever).
>
> ii) I've tended to use setBytes() instead of setBinaryStream() in the
> PreparedStatement object. Unsure if this matters, but I usally get passed
an
> array of bytes from the image uploading code. Streams may be more
efficient
> but I'm not sure if this is where the bug lies, if indeed it is a bug.
>
> Also, if you want to try out uploading/downloading the offending image I
can
> give you an account on our 'WebFormX' product site to see if its works
> against Postgres, basically builds online forms and you can upload form
> logos/backgrounds as well as image fields.
>
> Cheers,
> Joe
>
> > -----Original Message-----
> > From: The Hermit Hacker [mailto:scrappy@hub.org]
> > Sent: Sunday, 13 May 2001 2:45 AM
> > To: pgsql-jdbc@postgresql.org
> > Cc: peter@retep.org.uk
> > 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: scrappy@hub.org           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
> > majordomo@postgresql.org)
> >
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>


--
Subhramanya Shiva, Programmer
Archean InfoTech pvt.Ltd.
Hyderabad, India
http://www.archeanit.com



RE: Displaying/Pulling Images using JDBC ...

From
"Ho, Khanh"
Date:
Yes!! Thank you. That did the trick.
Khanh Ho.

> -----Original Message-----
> From: Bruce Momjian [mailto:pgman@candle.pha.pa.us]
> Sent: Monday, 14 May 2001 11:13 AM
> To: Ho, Khanh
> Cc: The Hermit Hacker; pgsql-jdbc@postgresql.org
> Subject: Re: [JDBC] Displaying/Pulling Images using JDBC ...
>
>
>
> 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:scrappy@hub.org]
> > > Sent: Sunday, 13 May 2001 2:45 AM
> > > To: pgsql-jdbc@postgresql.org
> > > Cc: peter@retep.org.uk
> > > 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: scrappy@hub.org           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
> > > majordomo@postgresql.org)
> > >
> >
> > ---------------------------(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
>   pgman@candle.pha.pa.us               |  (610) 853-3000
>   +  If your life is a hard drive,     |  830 Blythe Avenue
>   +  Christ can be your backup.        |  Drexel Hill,
> Pennsylvania 19026
>

Re: Compiling JDBC Driver - impossible!

From
Peter Eisentraut
Date:
Mike Cannon-Brookes writes:

> How do I compile the JDBC driver?

configure --with-java
make
make install

--
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter


Re: Compiling JDBC Driver - impossible!

From
"Dave Cramer"
Date:
Or....

move to the src/interfaces/jdbc directory

set your $JAVA_HOME to your jdk directory

and

make


Dave
----- Original Message -----
From: "Peter Eisentraut" <peter_e@gmx.net>
To: "Mike Cannon-Brookes" <mcannon@internet.com>
Cc: <pgsql-jdbc@postgresql.org>
Sent: Monday, May 14, 2001 11:01 AM
Subject: Re: [JDBC] Compiling JDBC Driver - impossible!


> Mike Cannon-Brookes writes:
>
> > How do I compile the JDBC driver?
>
> configure --with-java
> make
> make install
>
> --
> Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>
>


RE: Compiling JDBC Driver - impossible!

From
"Mike Cannon-Brookes"
Date:
Ok,

So here's a summary of the compile instructions so far:

1)
- move to the src/interfaces/jdbc directory
- set your $JAVA_HOME to your jdk directory
- run make

2)
- in root cvs directory
- configure --with-java
- make
- make install

3)
- use ant somehow?

I'm presuming all will work, I haven't had time to try any of them.

(This might be useful for someone to summarise somewhere on
jdbc.postgresql.org)

This seems a very convoluted build process IMHO.

-mike

Mike Cannon-Brookes - Founder, Core Developer
OpenSymphony - http://www.opensymphony.com
"The Open Source J2EE Component Project"

Latest News
- SiteMesh 1.2 Released!
http://www.opensymphony.com/sitemesh


Re: Compiling JDBC Driver - impossible!

From
"Dave Cramer"
Date:
Mike,

1 is a manual compile of the driver, 2 is the correct way, and will build
the driver and install it correctly; 3 is a wild stab at it.

In actual fact ant will be invoked by make. This is pretty straightforward.
I'm not sure what the confusion is about.

Dave
----- Original Message -----
From: "Mike Cannon-Brookes" <mcannon@internet.com>
To: <pgsql-jdbc@postgresql.org>
Sent: Monday, May 14, 2001 10:40 PM
Subject: RE: [JDBC] Compiling JDBC Driver - impossible!


> Ok,
>
> So here's a summary of the compile instructions so far:
>
> 1)
> - move to the src/interfaces/jdbc directory
> - set your $JAVA_HOME to your jdk directory
> - run make
>
> 2)
> - in root cvs directory
> - configure --with-java
> - make
> - make install
>
> 3)
> - use ant somehow?
>
> I'm presuming all will work, I haven't had time to try any of them.
>
> (This might be useful for someone to summarise somewhere on
> jdbc.postgresql.org)
>
> This seems a very convoluted build process IMHO.
>
> -mike
>
> Mike Cannon-Brookes - Founder, Core Developer
> OpenSymphony - http://www.opensymphony.com
> "The Open Source J2EE Component Project"
>
> Latest News
> - SiteMesh 1.2 Released!
> http://www.opensymphony.com/sitemesh
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>
>