I have a JSP page where I am loading data from a database in a loop. One of the database columns holds images stored as Blob. I am able to load all data from the database successfully when I don't try to load the image column.
When I load all data inclusive of images, only one image shows up on the page and no other data is shown on the page. Why is that so. As you can see from code, I have 5 columns of strings and 1 column of Blob. I should be getting each of this for 5 rows. I am looking for a solution for loading images dynamically and not hard code image path.
<body>
<div class="container">
<div class="row">
<%
String dbURL = "jdbc:mysql://1.1.1.1:3306/db_name";
String dbUser = "";
String dbPass = "";
Connection conn;
try{
DriverManager.registerDriver(new com.mysql.jdbc.Driver());
conn = DriverManager.getConnection(dbURL, dbUser, dbPass);
Statement statement = conn.createStatement();
ResultSet resultset =
statement.executeQuery("select image, name, age, gender, contact, description from tablename");
while(resultset.next()) {
Blob bl = resultset.getBlob(1);
byte[] pict = bl.getBytes(1,(int)bl.length());
response.setContentType("image/jpg");
OutputStream o = response.getOutputStream();
%>
<div class="col-sm-4">
<div class="k-cust_box">
<h3><%= resultset.getString(2) %></h3>
<hr>
<img class="k-profile-img" src="<%o.write(pict);%>" height="100px" border="1" style="float: left; overflow: hidden" width="33%">
<div class="k-driver-inner-box">
<h5>Age: <%= resultset.getString(3) %></h5>
<h5>Gender: <%= resultset.getString(4) %></h5>
<h5>Contact: <%= resultset.getString(5) %></h5>
</div>
<h5 class="k-fl-lt"><%= resultset.getString(6) %></h5>
</div>
</div>
<%}
}catch (Exception e){
e.printStackTrace();
}
%>
</div>
</div>
</body>