-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: How to Retrieve image from MySQL and display in jsp
PostPosted: Fri Jan 25, 2008 1:38 am 
Newbie

Joined: Thu Jan 24, 2008 1:24 am
Posts: 3
How to Retrieve image from MySQL and display it in jsp using struts and hibernate.I have saved it in MySQL using struts and hibernate,if anyone having example code then send it please.Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 29, 2008 12:04 pm 
Newbie

Joined: Sat Mar 29, 2008 11:12 am
Posts: 6
Location: USA
I have a similar issue and looking for a solution. If some one can advise on the right approach it will be really nice.

Any help would be greatly appreciated. Many thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 30, 2008 1:06 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi..

You need to use BLOB to achieve this...Refer the below link
http://www.hibernate.org/56.html
http://www.hibernate.org/73.html

Using Blob and Hibernate should be easy to do it...

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 30, 2008 2:27 pm 
Newbie

Joined: Sat Mar 29, 2008 11:12 am
Posts: 6
Location: USA
Hi

thanks for the reply. To save images in database I used approach described in the following post.

http://www.arunma.com/2007/03/01/upload ... hibernate/

And it works just fine. Now I need to implement a reverse action, i.e. access images stored in a database via JSP. In fact, I'm not a big s/w pro and have no hands on experience on such an implementation. Currently, I'm using Struts 1.3 with Hibernate 3.2 plus Tomcat 5.5 and MySQL 5.0.

Partial or whole working example for similar environment will be very helpful. Otherwise, please just suggest on solution that might work on your opinion assuming all the technologies I have.

Thank you in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 22, 2008 4:51 pm 
Newbie

Joined: Sat Mar 29, 2008 11:12 am
Posts: 6
Location: USA
Hi, can someone get into this issue and guide me how to deal with it? Please.

I'm still not able to see how to retrieve images stored in database as Blob. I'd need to display those in a JSP using Struts.

Any help would greatly appreciated. Thanks.


Top
 Profile  
 
 Post subject: Half solution
PostPosted: Wed Apr 30, 2008 7:36 am 
Newbie

Joined: Wed Apr 23, 2008 6:07 am
Posts: 5
hello,
I create a separate servlet that generates images:

doPost of Servlet:
Code:
String id = req.getParameter("id");

Blob image = //retrieve Blob from BD (can identifier with id).

OutputStream os = request.getOutputStream();

BufferedImage bi = ImageIO.read(image.getBinaryStream());

ImageIO.write(bi, "jpeg", os);



view that "jpeg" or "gif" or ....

on JSP page:
Code:
<img src="ImageServlet?id=${someId}" />


on web.xml:
mapping for ImageServlet.

Now, the problem is transaction management, whene page is loaded transactions close.. and image can be loaded later!. If begin transaction for this case, runs fine some pictures but with bd acces conflicts.

Some had the complete solution?? :).

PD: Sorry , my english is very bad ;).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 30, 2008 9:27 am 
Newbie

Joined: Wed Apr 23, 2008 6:07 am
Posts: 5
Hello another time,
the solution that comment this morning runs fine.
I had problems with transaction because retrieve the object that contains Blob inside, and later can't acces to this lazy member :P.
If when BD acces retrieve de Blob object directly, and open a new session
would have no problem.

Bye!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.