Fetch multiple images from mysql and show on a table

I want to fetch multiple images from mysql table and show it on a table.

Whats wrong with my code ? Here is my code

    <%@ page import="java.sql.*"%>

<%@ page import="java.io.*"%>

<%
response.setContentType("image/gif");
OutputStream o = response.getOutputStream();

Blob image = null;
//long   imgLen;
Connection con = null;

byte[ ] imgData = null ;

Statement stmt = null;

ResultSet rs = null;

try 
{

Class.forName("com.mysql.jdbc.Driver");

con = DriverManager.getConnection("jdbc:mysql://localhost:3306/document","root","root");

stmt = con.createStatement();

rs = stmt.executeQuery("select * from document_upload");
%>
<html>
<body>
<table border=2>
<tr>
<td>img
</td>

<%
while(rs.next()) 
{
    %>
    <td>

    <%
    image = rs.getBlob(1);
    imgData = image.getBytes(1,(int)image.length());
    o.write(imgData);%></td></tr></table>
    <%
} 

o.close();

} catch (Exception e)
{

out.println("Unable To Display image");

out.println("Image Display Error=" + e.getMessage());



}


%>

I am having problem that its showing only one image at a time. I tried to add table tags in while loop but still problem remains. The images are shown in layers that is one after another like..

Answers


The images are shown in layers that is one after another like..

Problem is with your basic html structure. Look at your while loop again, every time you loop through while loop, you are closing your row and table. You need to take closing of row and table out of the while loop.

This should fix it:

  <table border=2>
   <tr>
    <td>img</td>        
    <%
    while(rs.next()){
    %>
    <td>    
    <%
        image = rs.getBlob(1);
        imgData = image.getBytes(1,(int)image.length());
        o.write(imgData);
    %>
   </td>
    <%
     }    
   %>
 </tr>
</table>

Need Your Help

Overloading type cast operator, to cast to a pointer to function

c++ casting function-pointers

I'm having some difficulty, overloading the cast to pointer to function operator of a class. In code, what I want is this:

Change font color of ion-title in ionic 2

ionic-framework ionic ionic2

Hey I make a todo list app in ionic2, I have a sidebar list.