• Post Reply Bookmark Topic Watch Topic
  • New Topic

Retrieve Blob img from MySql and Display using servlet and jsp

 
Some Aditya Mandal
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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.
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • 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.
 
Dave Tolls
Ranch Hand
Posts: 2271
23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And there's no point getting the blob twice:
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!