Hi, I'm able to run the following code in the jsp. But my problem is I have multiple images in a table and would like all of it to be display as an icon. I have tried to put while(rs.next())... it doesn't work. How should I go about to do it. Thanks. Tan
<%@ page import="java.sql.*" %> <%@ page import="java.io.*" %> <%@ page import="javax.servlet.*" %> <%@ page import="javax.servlet.http.*" %> <%@ page import="javax.servlet.jsp.*" %> <% OutputStream os; String fn,sSQL,contentType,JDBC,DBURL,userName,pwd; int bufferSize=1048576,bytesRead=0; byte[] b = new byte[bufferSize]; ServletOutputStream sos; InputStream is; int fieldCount=0; ResultSet rs; Connection conn; Statement stmt; int fieldNo; Blob blob; BufferedInputStream bis; BufferedOutputStream bos; JDBC="org.gjt.mm.mysql.Driver"; DBURL="jdbc:mysql:///imaging"; userName="root"; pwd="password"; sSQL="select Bobject from blobber"; fn="1"; contentType="image/gif"; try {Class.forName(JDBC); conn=DriverManager.getConnection(DBURL,userName,pwd); stmt=conn.createStatement(); rs=stmt.executeQuery(sSQL); if (contentType==null) response.setContentType("image/gif"); else response.setContentType(contentType); if (fn==null) fieldCount=1; else fieldCount=Integer.parseInt(fn); rs.next(); blob= rs.getBlob(1); is=blob.getBinaryStream(); bis=new BufferedInputStream(is,2*bufferSize); sos=response.getOutputStream(); bos=new BufferedOutputStream(sos,2*bufferSize); bytesRead=bis.read(b,0,bufferSize); while (bytesRead!=-1) { bos.write(b,0,bytesRead); bytesRead=bis.read(b,0,bufferSize); } bis.close(); bos.close(); is.close(); sos.close(); rs.close(); stmt.close(); conn.close(); } catch (Exception e) { response.setContentType("text/html"); PrintWriter out1=response.getWriter(); out1.println("Servlet BlobHandler error occur:"+e.toString()); } %> __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php