[Pgsql-ayuda] fotos y los jsp...

Sebastián Benavides H. Sebastián Benavides H.
Sat, 10 May 2003 16:48:34 -0400


This is a multi-part message in MIME format.

------=_NextPart_000_0090_01C31713.FE9C9D00
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Esta pregunta me est=E1 dando dolores de cabeza...

Resulta que estoy trabajando con postgresql y j2ee (orion server =
especificamente).  Necesito insertar y recuperar imagenes (jpg, gif, y =
otros...) de la base de datos, estaba pensando hacer:

try {
        File fi =3D new File(defaultImageLocation + imageName);
        FileInputStream fis =3D new FileInputStream(fi);
        PreparedStatement ps =3D con.prepareStatement("INSERT INTO =
pilotos (id,image) values(?,'?')");
        ps.setInt(2,023);
        ps.setBinaryStream(1, fis, (int)fi.length());
       =20
        ps.execute();
        ps.close();
        fis.close();
      }
    }catch(SQLException sqle){
      System.out.println(sqle);
    }catch(IOException ioe){
      System.out.println(ioe);
    }

Donde id es un int y image es un bytea.
Esto me resulta, pero mi problema es la recuperaci=F3n de la imagen para =
ser mostrada en la web.

Ahora vi en la lista que era mejor ocupar un oid, pero al momento de =
recuperar los datos lo encuentro incomodo estar guardando los archivos =
en una carpeta, se pierde el uso de la BdD.=20

Si alguien sabe como o tiene otro metodo me lo puede hacer saber.
  Gracias amigos!
------=_NextPart_000_0090_01C31713.FE9C9D00
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1170" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Esta pregunta me est=E1 dando dolores =
de=20
cabeza...</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Resulta que estoy trabajando con =
postgresql y j2ee=20
(orion server especificamente).&nbsp;&nbsp;Necesito insertar y recuperar =

imagenes (jpg, gif, y otros...) de la base de datos, estaba pensando=20
hacer:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>try =
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
File fi =3D new File(defaultImageLocation +=20
imageName);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
FileInputStream fis =3D=20
new FileInputStream(fi);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
PreparedStatement ps =3D con.prepareStatement("INSERT INTO =
pilotos&nbsp;(id,image)=20
values(?,'?')");<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
ps.setInt(2,023);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=20
ps.setBinaryStream(1, fis,=20
(int)fi.length());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<BR=
>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
ps.execute();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
ps.close();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
fis.close();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;=20
}catch(SQLException sqle){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
System.out.println(sqle);<BR>&nbsp;&nbsp;&nbsp; }catch(IOException=20
ioe){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
System.out.println(ioe);<BR>&nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Donde id es un int y image es un=20
bytea.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Esto me resulta, pero mi problema es la =

recuperaci=F3n de la imagen para ser mostrada en la web.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Ahora vi en la lista que era mejor =
ocupar un oid,=20
pero al momento de recuperar los datos lo encuentro incomodo estar =
guardando los=20
archivos en una carpeta, se pierde el uso de la BdD. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Si alguien sabe como o tiene otro =
metodo me lo=20
puede hacer saber.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; Gracias =
amigos!</FONT></DIV></BODY></HTML>

------=_NextPart_000_0090_01C31713.FE9C9D00--