• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Retrive image from MySQL database in fix format on JSP page

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 not meddle in the affairs of dragons - for you are crunchy and good with ketchup. Crunchy tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic