Store image as rawbinary in database

in servlet set header:
 response.setContentType("image/gif");
or
 response.setContentType("image/jpeg");

then do something like this:

ServletOutputStream out = response.getOutputStream();
dbConnection.getImage(id,out)

in dbConnection retrieve retrieve the image from ResultSet like this:
InputStream fin = rset.getBinaryStream(1);
and loop to send to browser:

 for (i=0;;i++)    {
                  size = fin.read(buff);
                  out.write(buff);
                  if (size == -1) break;
}

close and say good bye

'is all

d.



Reto wrote:

> Hi
>
> How can I store an *.gif or *.jpg file in a Database
> and after display in a browser with servlet.
> Specialy, I d'ont now how to read the picture-file
> with a servlet and store this information in the
> attribut of database. After, I want read the image
> with a sevlet in the database and show in the browser.
> Have somebody examples of servletcode??
>
> Very thanks for help
>
> Reto
>
> __________________________________________________
> Do You Yahoo!?
> Talk to your friends online with Yahoo! Messenger.
> http://im.yahoo.com
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

--
David Mossakowski              [EMAIL PROTECTED]
Programmer                           212.310.7275
Instinet Corporation

"I don't sit idly by, I'm planning a big surprise"

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to