0

This is my class where I am obtaining connection

public class NewClass {
     getset gs=null;
     List<getset> list;

     public  List<getset> getdata() {
         list = new ArrayList<getset>();

         try {
             Class.forName("com.mysql.jdbc.Driver");
             Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/db","root","admin");
             PreparedStatement stmt = con.prepareStatement("select * from emp");
             ResultSet rs = stmt.executeQuery();

             while(rs.next()) {
                  gs = new getset();
                  gs.setId(rs.getInt(1));
                  gs.setMessage(rs.getString(2));
                  gs.setImages(rs.getBytes(3));

                  list.add(gs);
             }
        }
        catch (Exception e)
        {
             System.out.print(e);
        }

        return list;
    }
}

out.print("<table width=50% ><tr><td>ID</td><td>MESSAGE</td><td>IMAGES</td></tr>");

for(getset a:list) {
    out.print("<tr><td>"+a.getId()+"</td><td>"+a.getMessage()+"</td><td>"+
              "<a href=Servlet2>"+  "<img src="+a.getImages()+"  width=300 height=100 alt='Nothing to display'>"+"</td></tr>"+"</a>");
}
out.print("</table>");

I am trying to list images from database but it list only texts but not images

I have columns (id, message, image)

Could anyone please help me to reach out of it I cannot understand how to fix it

Can anyone please tell me more efficient way to retrieve images from database?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Shadow.m
  • 11
  • 3

0 Answers0