Advertisement
Guest User

Untitled

a guest
Dec 18th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. public static List<Picture> displayPicture() {
  2.  
  3. List<Picture> list = new ArrayList<Picture>();
  4.  
  5. try {
  6.  
  7. Class.forName("com.mysql.jdbc.Driver");
  8.  
  9. Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:9999/xxx", "xxx", "xxx");
  10.  
  11. String sql = "SELECT * FROM PICTURES";
  12.  
  13. PreparedStatement ps = conn.prepareStatement(sql);
  14.  
  15. ResultSet rs = ps.executeQuery();
  16.  
  17. while (rs.next()) {
  18.  
  19. byte[] imageData = rs.getBytes("File_Data");
  20. String imageFileName = rs.getString("File_Name");
  21.  
  22. Picture picture = new Picture();
  23. picture.setImageData(imageData);
  24. picture.setImageFileName(imageFileName);
  25. list.add(picture);
  26. }
  27.  
  28. } catch (Exception e) {
  29. e.printStackTrace();
  30. }
  31. return list;
  32.  
  33. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  34. List<Picture> list =null;
  35. list = DBUtils.displayPicture();
  36.  
  37. request.setAttribute("pictureList", list);
  38.  
  39. RequestDispatcher dispatcher = request.getServletContext().getRequestDispatcher("/WEB-INF/views/pictureView.jsp");
  40. dispatcher.forward(request, response);
  41.  
  42. <table>
  43. <c:forEach items="${pictureList}" var="picture">
  44. <tr>
  45. <td>${picture.imageData}</td>
  46. </tr>
  47. </c:forEach>
  48.  
  49. <img src="">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement