Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to display images directly from database?  RSS feed

 
Laxmikant Kumbhare
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating one application where i need to display images using <img> tag. It has other fields too. Please tell me the way to display images from database mysql which is at server, directly to my jsp page.
 
Anuj Batra
Greenhorn
Posts: 24
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%

int iNumPhoto ;
oracle.jdbc.driver.OracleConnection conn = null;

if ( request.getParameter("imgID") != null )
{

iNumPhoto = Integer.parseInt(request.getParameter("imgID")) ;

try
{
conn = …………;
conn.setAutoCommit (false);

// get the image from the database
byte[] imgData = photo.getPhoto( conn, iNumPhoto ) ;
// display the image
response.setContentType("image/gif");
OutputStream o = response.getOutputStream();
o.write(imgData);
o.flush();
o.close();
}
catch (Exception e)
{
e.printStackTrace();
throw e;
}
finally
{
… Close the connexion … ;
}
}
%>
 
Laxmikant Kumbhare
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
on which object you are calling getphoto method
 
Gopakumar Naryanan
Ranch Hand
Posts: 72
Eclipse IDE Hibernate Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Laxmikant Kumbhare wrote:on which object you are calling getphoto method


There must be some variable with id "photo" in some specific scope.
He didn't post it.

Anyway, use the following link and change it according to your requiement.

http://www.roseindia.net/servlets/retreiveimage.shtml

Hope this will help you.

Let me know if anything required further.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!