Received: from mail.ikasths.dk (mail.ikasths.dk [212.237.188.3]) by hub.org (8.10.1/8.10.1) with ESMTP id e95BE2789028 for ; Thu, 5 Oct 2000 07:14:02 -0400 (EDT) Received: from pc4151 ([212.237.191.151]) by mail.ikasths.dk (Post.Office MTA v3.5.2 release 221 ID# 0-62113U3000L300S0V35) with SMTP id dk for ; Thu, 5 Oct 2000 13:13:52 +0200 Message-ID: <004f01c02ebd$8f30a380$97bfedd4@pc4151> From: tjm2@mail.ikasths.dk (Troels Jegbjaerg Moerch) To: "psql" References: <39DC5F29.E9F4023@dif.um.es> Subject: Re: wrong documentation and others ..... Date: Thu, 5 Oct 2000 13:15:24 +0200 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_004C_01C02ECE.527ABCD0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Archive-Number: 200010/14 This is a multi-part message in MIME format. ------=_NextPart_000_004C_01C02ECE.527ABCD0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi try this:=20=20=20 File file =3D new File("myimage.gif");=20 FileInputStream fis =3D new FileInputStream(file);=20 byte[] theByteArray =3D new byte[fis.available()]; fis.read(theByteArray); =20=20=20 PreparedStatement ps =3D con.prepareStatement("insert insert into images= values (?,?)"); ps.setString(1,file.getName());=20 ps.setBytes(2, theByteArray); ps.execute(); con.commit(); ps.close(); fis.close(); =20=20=20 TJM ----- Original Message -----=20 From: Gabriel Lopez=20 To: psql=20 Sent: Thursday, October 05, 2000 12:59 PM Subject: [INTERFACES] wrong documentation and others ..... =20=20=20=20 Hi all.=20 I have several days working with LargeObject and postgres 7.0.2 and I= have found many problems. In the first time the postgresql doc is wrong, i= n chapter 58 of PosgreSQL tutorial (JDBC Interfaces) it repot who to work w= ith Large Object and give code that is wrong:=20 File file =3D new File("myimage.gif");=20 FileInputStream fis =3D new FileInputStream(file);=20 PreparedStatement ps =3D conn.prepareStatement("insert into image= s values (?,?)");=20 ps.setString(1,file.getName());=20 ps.setBinaryStream(2,fis,file.length());=20 ps.executeUpdate();=20 ps.close();=20 fis.close();=20 PreparedStatement ps =3D con.prepareStatement("select oid from im= ages where name=3D?");=20 ps.setString(1,"myimage.gif");=20 ResultSet rs =3D ps.executeQuery();=20 if(rs!=3Dnull) {=20 while(rs.next()) {=20 InputStream is =3D rs.getBinaryInputStream(1);=20 // use the stream in some way here=20 is.close();=20 }=20 rs.close();=20 }=20 ps.close();=20 =20=20=20=20 InputStream ARE NOT SUPPORTED in JDBC implementation =A1=BF?=A1 a= nd "getBinaryInputStream()" really is "getBinaryStream()". I think that it= is very serious. The other method (that I know) is using LargeObjectAPI, b= ut this fail every 9 times of PreparedStatement of setObject() sentence =A1= =A1=A1 and when use LargeObjectManager as in source examples. (I send other= messages to list)=20 =20=20=20=20 Has PostgreSQL any way to work WELL with LargeObject.?=20 Please reply me.=20 Cheers, Gabi.=20 =20=20=20=20 --=20 Gabriel L=F3pez Mill=E1n=20=20=20=20 Facultad de Inform=E1tica -Universidad de Murcia 30001 Murcia - Espa=F1a (Spain) Telf: +34-968-364644 E-mail: gabilm@dif.um.es =20=20=20=20 ------=_NextPart_000_004C_01C02ECE.527ABCD0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Hi try this:   
 
   File file =3D new=20 File("myimage.gif"); 
   FileInputStream fis =3D new= =20 FileInputStream(file);

   byte[] theByteArray = =3D new=20 byte[fis.available()];
   fis.read(theByteArray);
&nbs= p;  
   PreparedStatement=20 ps =3D con.prepareStatement("insert insert into images values=20 (?,?)");
 
  =20 ps.setString(1,file.getName()); 
   ps.setBytes(2,= =20 theByteArray);
   ps.execute();
   con.= commit();
   ps.close();
   fis.close()= ;
   
 
 
TJM
 
 
 
----- Original Message -----
Fro= m:=20 Gabriel Lope= z=20
To: psql
Sent: Thursday, October 05, 2000 1= 2:59=20 PM
Subject: [INTERFACES] wrong docume= ntation=20 and others .....

 =20

    Hi all.=20

    I have several days working with LargeObject and=20 postgres 7.0.2 and I have found many problems. In the first time the=20 postgresql doc is wrong, in chapter 58 of PosgreSQL tutorial (JDBC Interf= aces)=20 it repot who to work with Large Object and give code that is wrong:=20

        File file =3D new=20 File("myimage.gif");
       =20 FileInputStream fis =3D new FileInputStream(file);=20
        PreparedStatement ps =3D= =20 conn.prepareStatement("insert into images values (?,?)");=20
        ps.setString(1,file.getNam= e());=20
       =20 ps.setBinaryStream(2,fis,file.length());=20
        ps.executeUpdate();=20
        ps.close();=20
        fis.close();=20

        PreparedStatement ps =3D=20 con.prepareStatement("select oid from images where name=3D?");=20
        ps.setString(1,"myimage.gi= f");=20
        ResultSet rs =3D=20 ps.executeQuery();
        if(rs!= =3Dnull)=20 {
           = =20 while(rs.next()) {=20
           &nb= sp;   =20 InputStream is =3D rs.getBinaryInputStream(1);=20
           &nb= sp;   =20 // use the stream in some way here=20
           &nb= sp;   =20 is.close();=20
           &nb= sp;   =20 }
           = =20 rs.close();
        }=20
        ps.close();
 =20

        InputStream ARE NOT SUPPORT= ED in=20 JDBC implementation =A1=BF?=A1 and "getBinaryInputStream()" really is=20 "getBinaryStream()".  I think that it is very serious. The other met= hod=20 (that I know) is using LargeObjectAPI, but this fail every 9 times of=20 PreparedStatement of setObject() sentence =A1=A1=A1 and when use LargeObj= ectManager=20 as in source examples. (I send other messages to list)
 =20

        Has PostgreSQL any way to w= ork=20 WELL with LargeObject.?=20

    Please reply me.=20

    Cheers, Gabi.
 

-- 
Gabriel L=F3pez Mill=E1n    
Facultad de Inform=E1tica -Universidad de Murcia
30001 Murcia - Espa=F1a (Spain)
Telf: +34-968-364644 E-mail: gabilm@dif.um.es
 =20 ------=_NextPart_000_004C_01C02ECE.527ABCD0--