I am displaying data is a jsp page from "resultset.getString("column_name")" attribute which works fine for my columns.
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.io.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="javax.servlet.http.*"%>
<%@ page import="javax.servlet.http.HttpSession"%>
<%@ page language="java"%>
<%@ page session="true"%>
<%@ page import="java.sql.*"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.Connection"%>
<%@page import="javax.servlet.ServletOutputStream"%>
<style>
th, td {
padding: 15px;
}
</style>
<%
String id = request.getParameter("name");
String driverName = "com.mysql.jdbc.Driver";
String connectionUrl = "jdbc:mysql://localhost:3306/";
String dbName = "employee";
String userId = "root";
String password = "root";
try {
Class.forName(driverName);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
String iurl1=null;
Blob employee_dp=null;
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
%>
<h2 align="center"><font><strong>Retrieve data from database in jsp</strong></font></h2>
<%
try {
connection = DriverManager.getConnection(connectionUrl + dbName, userId, password);
statement = connection.createStatement();
String sql = "SELECT * FROM employee_details where ID='" + session.getAttribute("ID") + "'";
resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
%>
<table border="0" class="display" >
<tbody>
<tr>
<td>ID : </td>
<td><%=resultSet.getString("ID")%></td>
</tr>
<tr>
<td>First Name : </td>
<td><%=resultSet.getString("name")%></td>
</tr>
<tr>
<td>Last Name : </td>
<td><%=resultSet.getString("Last_Name")%></td>
</tr>
<tr>
<td>D.O.B. : </td>
<td><%=resultSet.getString("DOB")%></td>
</tr>
<tr>
<td>image : </td>
<td><img alt="Smiley face" src="<%=resultSet.getString("employee_dp") %>" width="500" height="500"/></td>
</tr>
<tr>
<td>Attach address proof </td>
<td> <input type="file" name="txtfile"> </td>
</tr>
</tbody>
</table>
<%}}
catch (Exception e) {
out.println("DB problem");
return;
}
finally {
try {
resultSet.close();
statement.close();
connection.close();
}
catch (SQLException e) {
e.printStackTrace();
}
}
%>
Here is the code for my jsp displaying page. Driver code to this is a basic login page which redirects to my this jsp page. I changed the code a bit and tuned it to see if my image is available or not. I tried by just giving the direct destination under "src" tag , it worked but when i retrieve it through resultSet.getString(column_name) it shows bits of symbols. If i use .getBlob I get a empty image box