Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  7.  
  8. <title>Picture preview</title>
  9.  
  10. <meta http-equiv="refresh" content="5">
  11. </head>
  12.  
  13. <body>
  14.  
  15.  
  16.  
  17.  
  18.  
  19. <%@ page import="java.sql.*"%>
  20.  
  21. <%@ page import="java.io.*"%>
  22.  
  23.  
  24. <%
  25. // int randomWithRange=(int)(Math.random() * (9) + 2);
  26. //maxid-minid+1 prva zagrada druga zagrada minid
  27.  
  28. Blob image = null;
  29.  
  30. Connection con = null;
  31.  
  32. byte[] imgData = null;
  33.  
  34. Statement stmt = null;
  35.  
  36. ResultSet rs = null;
  37.  
  38. ResultSet min = null;
  39. ResultSet max = null;
  40.  
  41. try {
  42.  
  43. Class.forName("com.mysql.jdbc.Driver");
  44.  
  45. con = DriverManager.getConnection("jdbc:mysql://localhost:3306/rentacar", "root", "root");
  46.  
  47. stmt = con.createStatement();
  48.  
  49. // rs = stmt.executeQuery("select file from files where id = '"+randomWithRange+"'");
  50. rs = stmt.executeQuery("select file from files order by RAND()");
  51.  
  52. if (rs.next()) {
  53.  
  54. image = rs.getBlob(1);
  55.  
  56. imgData = image.getBytes(1, (int) image.length());
  57.  
  58. } else {
  59.  
  60. out.println("Display Blob Example");
  61.  
  62. out.println("image not found for given id>");
  63.  
  64. return;
  65.  
  66. }
  67.  
  68. // display the image
  69.  
  70. response.setContentType("image/gif");
  71.  
  72. OutputStream o = response.getOutputStream();
  73.  
  74. o.write(imgData);
  75.  
  76. o.flush();
  77.  
  78. o.close();
  79.  
  80. } catch (Exception e) {
  81.  
  82. out.println("Unable To Display image");
  83.  
  84. out.println("Image Display Error=" + e.getMessage());
  85.  
  86. return;
  87.  
  88. } finally {
  89.  
  90. try {
  91.  
  92. rs.close();
  93.  
  94. stmt.close();
  95.  
  96. con.close();
  97.  
  98. // Thread.sleep(1000);
  99. response.setHeader("Refresh", "300");
  100.  
  101. } catch (SQLException e) {
  102.  
  103. e.printStackTrace();
  104.  
  105. }
  106.  
  107. }
  108. %>
  109. </body>
  110. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement