Advertisement
Guest User

Untitled

a guest
Apr 11th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. <%
  2. --
  3. Document : roseindiabiob
  4. Created on : Apr 11, 2017, 10:55:59 AM
  5. Author : sumaiya
  6. --%>
  7. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  8. <%@ page import="java.sql.*"%>
  9. <%@ page import="java.io.*"%>
  10. <% Blob image = null;
  11.  
  12. Connection con = null;
  13. byte[] imgData = null;
  14. Statement stmt = null;
  15. ResultSet rs = null;
  16.  
  17. try {
  18. Class.forName("com.mysql.jdbc.Driver");
  19. con = DriverManager.getConnection("jdbc:mysql://localhost:3306/uploading","root","");
  20. stmt = con.createStatement();
  21. rs = stmt.executeQuery("select bImage from upload_image where iImageID = '1'");
  22. if (rs.next()) {
  23. image = rs.getBlob(1);
  24. imgData = image.getBytes(1,(int)image.length());
  25. } else {
  26. out.println("Display Blob Example");
  27. out.println("image not found for given id>");
  28. return;
  29. }
  30.  
  31. // display the image
  32.  
  33. response.setContentType("image/gif");
  34. OutputStream o = response.getOutputStream();
  35. %>
  36.  
  37.  
  38. <html><head><%o.write(imgData);%></head></html>
  39. <%
  40. o.flush();
  41. o.close();
  42. } catch (Exception e) {
  43. out.println("Unable To Display image");
  44. out.println("Image Display Error=" + e.getMessage());
  45. return;
  46. } finally {
  47. try {
  48. rs.close();
  49. stmt.close();
  50. con.close();
  51. } catch (SQLException e) {
  52. e.printStackTrace();
  53. }
  54.  
  55. }
  56.  
  57. %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement