Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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>
                <td>ID : </td>
                <td><%=resultSet.getString("ID")%></td>
                <td>First Name : </td>
                <td><%=resultSet.getString("name")%></td>
                <td>Last Name : </td>
                <td><%=resultSet.getString("Last_Name")%></td>
                <td>D.O.B. : </td>
                <td><%=resultSet.getString("DOB")%></td>
                <td>image : </td>
                  <td><img alt="Smiley face" src="<%=resultSet.getString("employee_dp") %>" width="500" height="500"/></td>
                <td>Attach address proof </td>
                <td>  <input type="file" name="txtfile"> </td>
        </tbody>
    </table>

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

If i use .getString I get a lot of symbols

Try adding the problem statement, current progress, actual output and desired output to the question to make it understandable. – anees Apr 30, 2020 at 17:14 @AneesIjaz ,thank you for responding,I have added my code and my issue with the two statements as well. – Pranav Sharma May 1, 2020 at 11:20 @Swati ,thank you maam it helped me a lot to gain knowledge, While i gained another aproach to do so . I did it by adding images in a folder in my project folder and then i named it same as primary key and used to retrieve it by .getString("column name") so i used the command <td><button><img class="icon" src="images/<%=resultSet.getString("ID") %>.png" width="200" height="200" alt="edit"></button> </td> This solved my purpose. – Pranav Sharma May 4, 2020 at 12:08

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.