Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%
- --
- Document : roseindiabiob
- Created on : Apr 11, 2017, 10:55:59 AM
- Author : sumaiya
- --%>
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <%@ page import="java.sql.*"%>
- <%@ page import="java.io.*"%>
- <% Blob image = null;
- Connection con = null;
- byte[] imgData = null;
- Statement stmt = null;
- ResultSet rs = null;
- try {
- Class.forName("com.mysql.jdbc.Driver");
- con = DriverManager.getConnection("jdbc:mysql://localhost:3306/uploading","root","");
- stmt = con.createStatement();
- rs = stmt.executeQuery("select bImage from upload_image where iImageID = '1'");
- if (rs.next()) {
- image = rs.getBlob(1);
- imgData = image.getBytes(1,(int)image.length());
- } else {
- out.println("Display Blob Example");
- out.println("image not found for given id>");
- return;
- }
- // display the image
- response.setContentType("image/gif");
- OutputStream o = response.getOutputStream();
- %>
- <html><head><%o.write(imgData);%></head></html>
- <%
- o.flush();
- o.close();
- } catch (Exception e) {
- out.println("Unable To Display image");
- out.println("Image Display Error=" + e.getMessage());
- return;
- } finally {
- try {
- rs.close();
- stmt.close();
- con.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement