permaculture playing cards*
The moose likes JSP and the fly likes insert  view, images  from mysql database using jsp program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "insert  view, images  from mysql database using jsp program" Watch "insert  view, images  from mysql database using jsp program" New topic
Author

insert view, images from mysql database using jsp program

maheshm morem
Greenhorn

Joined: Sep 23, 2010
Posts: 26
hi,
i am trying to insert , view the images from mysql database but it inserts the images but does not display the all images , it display only one first image , so what i have to do?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Can you show us some of your code?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
maheshm morem
Greenhorn

Joined: Sep 23, 2010
Posts: 26
<%@page language="java" import="java.sql.*, java.io.*" %>
<html>
<body>

<%
Connection connection = null;
ResultSet rs = null;
Statement st = null;
try {

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
connection = DriverManager.getConnection("jdbcdbc:mm1", "root", "mahesh");
st=connection.createStatement();
InputStream sImage;
rs = st.executeQuery("select * from save_image");
while(rs.next())
{

byte[] bytearray = new byte[1048576];
int size=0;
sImage = rs.getBinaryStream(1);
response.reset();
response.setContentType("image/jpeg");
while((size=sImage.read(bytearray))!= -1 ){
response.getOutputStream().write(bytearray,0,size);
}

}
}

catch (Exception ex) {
out.println("Found some error : "+ex);
}
finally {
// close all the connections.
//connection.close();
//psmnt.close();
}

%>
</body>
</html>
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2497
    
    8

What is the effect of this line, which you call every time you loop:
response.reset();
?

JSPs are not made to create binary output. They are not your tool to display images.
Would it not be easier to create a servlet that serves the images from the database,
and that your jsp page calls that servlet in an <img> tag?

Another thread on the same topic:
http://www.coderanch.com/t/292437/JSP/java/display-image-after-retrieving-it

I am moving this post to our JSP forum for you.

OCUP UML fundamental and ITIL foundation
youtube channel
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: insert view, images from mysql database using jsp program