• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Retrive image from MySQL database in fix format on JSP page  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all.

My problem is like this- I am storing image in MySQL database and now i have to retrieve those image on my JSP page. I am able to retrieve those image on JSP page but the problem is that i cant fix those size. Image is being retrieved in their original format only. Can anyone tell me how can i put them in fixed format???

Thanks in advance.
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rutvi,

Can you please post some of your code, and the format of the images in the database and the "FIXED" format to be displayed in jsp ? That will help us a lot ...as to how it can be solved?
 
rutvi gen
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection( "jdbc:mysql://192.168.4.29:3306/pts?","root","root");
PreparedStatement pst = conn.prepareStatement("SELECT image FROM image WHERE devID = ?");
pst.setString(1, "dv11");
ResultSet rs = pst.executeQuery();
if(rs.next()) {
byte[] bytearray = new byte[1048576];
int size=0;
InputStream sImage;
sImage = rs.getBinaryStream(1);
response.reset();
response.setContentType("image/jpeg");
response.addHeader("Content-Disposition","filename=logo.jpg");
while((size=sImage.read(bytearray))!= -1 )
{
%>
<table border="1">
<tr>
<td width="100" height="100">
<%
response.getOutputStream().write(bytearray,0,size);
%>
</td>
</tr>
</table>
<%
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You appear to be mixing HTML tags with binary image data. Think about it! When a browser sees an IMG tag it starts a separate request to get the image data only.

Serving binary data should be done from a servlet, JSP is for character data. The response outputStream is trying to send character data.

MANY MANY posts on this forum have covered this problem, do some searching.

Bill
 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!