*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 2491
    
    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
 
Similar Threads
insert ,delete ,update images from mysql database using jsp program
How to store & retrieve a video file from database?
jsp and mysql error
Question on VIEW
How to display images directly from database?