Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to display multiple images and data from mysql in jsp
    primarykey
    data
    text
    <p>I am using jsp with mysql in these code. i got only one images at a time but all data retrieved... Can u tell me how to display multiple images in this code? my data: imagename varchar(),description varchar(),imageid varchar(),category varchar image blob(). index.jsp:</p> <pre><code> &lt;%@page import="java.io.InputStream"%&gt; &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt; &lt;%@page import="java.io.OutputStream"%&gt;`` &lt;%@ page import="java.sql.*" %&gt; &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;title&gt;JSP Page&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;% Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager. getConnection("jdbc:mysql://localhost:3306/rich","root",""); Statement stmt = con.createStatement(); ResultSet rs=stmt.executeQuery("select *from publishers"); while(rs.next()) { String imgLen=rs.getString(5); int len = imgLen.length(); byte [] rb = new byte[len]; InputStream readImg = rs.getBinaryStream(5); int index=readImg.read(rb, 0, len); System.out.println("index"+index); stmt.close(); response.reset(); response.setContentType("image/jpg"); response.getOutputStream().write(rb,0,len); response.getOutputStream().flush(); } %&gt; &lt;/body&gt; &lt;/html&gt; **basic.jsp:** &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt; &lt;%@page import="java.io.OutputStream"%&gt; &lt;%@ page import="java.sql.*" %&gt; &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;title&gt;JSP Page&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt; form action="index.jsp" method="post"&gt; &lt;% Class.forName("com.mysql.jdbc.Driver"); Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/rich","root",""); Statement stmt = con.createStatement(); ResultSet rs=stmt.executeQuery("select *from publishers"); while(rs.next()) { %&gt; &lt;table border="1"&gt; &lt;tr&gt; &lt;td&gt; &lt;img src="index.jsp?" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;%=rs.getString(1)%&gt; &lt;/td&gt; &lt;td&gt; &lt;%=rs.getString(2)%&gt; &lt;/td&gt; &lt;td&gt; &lt;%=rs.getString(3)%&gt; &lt;/td&gt; &lt;td&gt; &lt;%=rs.getString(4)%&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;% } %&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload