Guest User

Untitled

a guest
Jan 27th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
  2. {
  3. Enfants enfants = new Enfants();
  4.  
  5. //PrintWriter pw = response.getWriter();
  6. int id = Integer.parseInt(request.getParameter("id"));
  7.  
  8. String url = "jdbc:mysql://localhost:3307/suzieloveschildren";
  9. String username = "root";
  10. String password = "";
  11. String driverName = "com.mysql.jdbc.Driver";
  12. try {
  13. Class.forName(driverName);
  14. Connection connection = DriverManager.getConnection(url, username, password);
  15. String sql = "SELECT Profile_Pic FROM enfants WHERE id= " + id ;
  16. System.out.println(sql);
  17. PreparedStatement stmt = connection.prepareStatement(sql );
  18. ResultSet rs = stmt.executeQuery();
  19. if (rs.next())
  20. {
  21. byte barray [] = rs.getBytes(1);
  22. response.setContentType("image/png");
  23.  
  24. //System.out.println("Base64 data is " + barray);
  25.  
  26. OutputStream img = response.getOutputStream();
  27.  
  28. img.write(barray);
  29. img.flush();
  30. img.close();
  31.  
  32. }
  33. }
  34. catch(Exception ex) {
  35.  
  36. }
  37. }
  38.  
  39. <img style="max-width: 300px;max-height: 300px;" src="ViewEnfants?id=${enfants.id}" />
  40.  
  41. http://localhost:8080/slc/ViewEnfants?id=223
Add Comment
Please, Sign In to add comment