retrieve image from my sql database using jsp

I want to retrieve image from my sql (blob type) & save it in given relative path in server .(using jsp and servlets)please give me some sample codes.
[168 byte] By [DAANa] at [2007-11-27 1:42:02]
# 1

Heres a better plan.

How about you write some of your own code, and post back here if you have trouble?

Or google for sample codes?

It breaks down rather simply

1 - Determine file to write to (use ServletContext.getRealPath() method)

2 - retrieve BLOB from database into byte array using java.sql package.

3 - write byte array to file using java.io package.

evnafetsa at 2007-7-12 0:58:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

PreparedStatement pst = null;

ResultSet rs=null;

pst = conn.prepareStatement("select image from imagedetails where imageid='"+imageid+"'");

rs=pst.executeQuery();

while(rs.next())

{

byte[] b=rs.getBytes("image");

FileOutputStream fos=new FileOutputStream("c://image.jpg");

fos.write(b);

}

hi this the code to retrieve the image from DB and write to a file.

kamal_shana at 2007-7-12 0:58:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...