672329 members! Sign up to stay informed.

Sponsored Links


Resources

Enterprise Java
Research Library

Get Java white papers, product information, case studies and webcasts

Web tier: servlets, JSP, Web frameworks Web tier: servlets, JSP, Web frameworks Web tier: servlets, JSP, Web frameworks Messages: 1 Messages: 1 Messages: 1 Printer friendly Printer friendly Printer friendly Post reply Post reply Post reply XML XML XML

How to Display Images in JSP retrieved from database using blob

Posted by: Sreenivasa Murthy on April 03, 2001 DIGG
hi

i want to display the image stored in the database, i am storing as blob, i am able to retrieve the image and i want to display it in the jsp page , can u just give either the code or sample how to do it.

thanks in advance
srini
  Message #17482 Post reply Post reply Post reply Go to top Go to top Go to top

How to Display Images in JSP retrieved from database using blob

Posted by: Stefan Seifert on April 06, 2001 in response to Message #17104
Hello Srini.

Take a look at the following JSP Page. Important ist the setting of the ContentType for the response header, i.e. to "image/gif" or "image/jpeg" (in this case a database field, too).

<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%

  Class.forName("com.inet.tds.TdsDriver").newInstance();
  Connection con = DriverManager.getConnection("jdbc:inetdae7:encharmion_nt4?database=RS", "Vignette", "vignette");

  String strSQL = "SELECT ContentType, ImageBinary "
    + "FROM Images "
    + "WHERE (ImageID=" + request.getParameter("imageid") + ")";
  Statement stmt = con.createStatement();
  ResultSet rs = stmt.executeQuery(strSQL);
  rs.next();

  response.setHeader("expires", "0");
  response.setContentType(rs.getString("ContentType"));

  out.clear();
  OutputStream os = response.getOutputStream();
  os.write(rs.getBytes("ImageBinary"));
  out.flush();
  return;

%>

This is only a test page, of course you should use some kind of connection pooling etc. in production sites.

Stefan



Recent active threads Recent active threads Recent active threads More More More
“Father of Java” James Gosling to keynote at TSSJS 2010
Oracle's Bold Plans for Java Bode Well
typo in faces-config to-view-id extension, but works fine?
BUY FAKE PASSPORTS OF CANADA, FAKE CANADIAN PASSPORTS FOR SALE/FAKE PASSPORTS OF USA!
BUY FAKE PASSPORTS OF UNITED KINGDOM,FAKE UK PASSPORTS FOR SALE!
BUY FAKE PASSPORTS OF CANADA, FAKE CANADIAN PASSPORTS FOR SALE!
BUY FAKE PASSPORTS OF BELGIAN,FAKE BELGIUM PASSPORTS FOR SALE!
BUY FAKE PASSPORTS OF AUSTRALIA/FAKE AUSTRALIAN PASSPORTS FOR SALE!
Milton 1.5.1 released
More active threads »
Top posters of the weekTop posters of the weekTop posters of the week
This list contains the members who have made the most posts in all forums over the last 7 days:
  1. Reza Rahman
  2. James Watson
  3. brad mcevoy
  4. Alex Besogonov
  5. Peter Monks
Hot threads Hot threads Hot threads More hot threads More hot threads More hot threads

Object pooling is now a serious performance loss

Brian Goetz continues to lift the lid and peak into the inner workings of Java in Java Urban Performance Legends. In this article he exposes the fallacy behind some of the more common performance myths found in the annals of the JVM.
(92 comments, last posted March 14, 2008)

Beyond Java

Bruce Tate, author of Better, Faster Lighter Java and Bitter EJB has come out with a new book called Beyond Java. Bruce has an epiphany about the future of software development. Does it include Java?
(770 comments, last posted September 23, 2009)

Three forms of AJAX: solid, liquid and gas.

Looks like today AJAX concept have several interpretations. We can distinguish different approaches of AJAX integration. Can they co-exist within the same application? Can we talk about layered AJAX integration?
(68 comments, last posted May 08, 2008)

Design-Time API Promises to make Java more like VB

Artima has published a short article describing the Design-Time API for JavaBeans, which was recently approved as JSR 273. This API promises to bring VB-like ease to Java development, but may face a cultural bias among Java developers who tend to think more in terms of class libraries than components.
(226 comments, last posted February 01, 2010)

Will Sun be that target of a management buyout?

There is plenty of speculation today regarding a potential buyout of Sun Microsystems by Scott McNealy and Silver Lake Partners. How would privatization of Sun affect Java?
(16 comments, last posted May 15, 2009)
More hot threads »

News | Blogs | Discussions | Tech talks | Patterns | Reviews | White Papers | Downloads | Articles | Media kit | About
Java Solutions
All Content Copyright ©2007 TheServerSide Privacy Policy      Powered by JIVE
Site Map