• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Retrieve Blob img from MySql and Display using servlet and jsp

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Table :-

create table imagedb (usd varchar(255) , image blob , primary key (usd), foreign key (usd) references logindb(user) on update cascade on delete cascade)

Using JSP i am able to upload the file into the blob. But icant retrieve or display;

The HTML Tag :


<table style="margin: 0px; margin-top: 15px;">
<tr>
<td id="photo">
<img src="displayimage" />
</td>

</tr>

The Servlet




I am not getting the image. Help.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

What does "I am not getting the image" mean, exactly? What is or is not happening as you execute this code? What are the values of the involved variables? Note that using System.out.println with images, streams and arrays isn't likely to produce anything useful. Also note that ResultSet.getString doesn't work with blobs. Lastly, note that the code is wide open to SQL injection attacks; you need to use PreparedStatement.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And there's no point getting the blob twice:
 
Sheriff
Posts: 67747
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can also enter the URL for the image servlet directly into the address bar, and if all is well, you will see the image. That diagnoses whether the problem is in the servlet, or the HTML.

Your image reference in the HTML is suspect: it should be server-relative starting with the context path. Page-relative URLs are fragile and problematic in Java web apps.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic