Jump to content

How to view all images stored in database using JSP?

i have 10 images in my database table and i want to display all those images in a jsp page. i have tried this code .it displays the last image in the database only in all 10 places. i have attached a image so that u can see how it appears. only the Toshiba logo which is the last image stored in the DB is showing in all positions. i want to show all the images in descending order. 

 

 <%
                Class.forName("com.mysql.jdbc.Driver");
                Connection conn = null;
                conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/testdb", "root", "root");
                Statement stmt = null;
                stmt = conn.createStatement();
                String query = "select * from products order by ID DESC ";
                ResultSet rs = null;
                rs = stmt.executeQuery(query);
                while(rs.next()){
            %>
            <tr>
                <%
                    String name = rs.getString("Name");
                   String Price = rs.getString("Price");
                   String imge = "viewitemimageservlet?image1";
                   
                %>
             
                <td><%=name %></td>
                <td><%=Price %></td>
                <td>
                    
                    <img src="viewitemimageservlet?<%=imge %> " width="400" height="200" />
                  
                  }

 

tosh.PNG

Link to comment
Share on other sites

Link to post
Share on other sites

Not sure + I can only get PHP somewhat to work. But I think you should add the HTML code inside your loop. Currently it seems to go trough all images, but has nothing to do with them images. Only the last entry gets stored, and thus used. But that's all I can see, and I don't know anything about this language.

 

Edit: wait, what? It is included in the while statement? No clue then. Sorry for waisting your time.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×