Advertisement
Guest User

Untitled

a guest
Feb 12th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. <%@ page import="java.sql.*"%>
  2. <%@ page import="java.io.*"%>
  3.  
  4. <% Blob image = null;
  5. Connection con = null;
  6. byte[] imgData = null ;
  7. Statement stmt = null;
  8. ResultSet rs = null;
  9.  
  10. try {
  11. Class.forName("com.mysql.jdbc.Driver");
  12. con = DriverManager.getConnection("jdbc:mysql://127.0.0.1/abc","root","123");
  13. stmt = con.createStatement();
  14. rs = stmt.executeQuery("select * from image");
  15. if (rs.next()) {
  16. image = rs.getBlob(2);
  17. imgData = image.getBytes(1,(int)image.length());
  18. } else {
  19. out.println("Display Blob Example");
  20. out.println("image not found for given id>");
  21. return;
  22. }
  23.  
  24. // display the image
  25. response.setContentType("image/png");
  26. OutputStream o = response.getOutputStream();
  27. o.write(imgData);
  28. o.flush();
  29. o.close();
  30. } catch (Exception e) {
  31. out.println("Unable To Display image");
  32. out.println("Image Display Error=" + e.getMessage());
  33. return;
  34. } finally {
  35. try {
  36. rs.close();
  37. stmt.close();
  38. con.close();
  39. } catch (SQLException e) {
  40. e.printStackTrace();
  41. }
  42. }
  43. %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement