JSP/SERVLET
2010.09.16 / 15:24

JPGÀúÀåµÈµðºñÀ̹ÌÁö JSP·Î º¸¿©ÁÖ±â

¸Þ±â
Ãßõ ¼ö 272
Á¦¸ñ¾øÀ½
JPGÀúÀåµÈµðºñÀ̹ÌÁö JSP·Î º¸¿©ÁÖ±â

<%@ page language="java" contentType="image/jpeg" %>
<%@ page import="java.util.*, java.sql.*, java.io.*" %>
<%
  String sql = "";
  Connection con = null;
  PreparedStatement pstmt = null;
  ResultSet rs = null;

  OutputStream output = response.getOutputStream();
  InputStream input = null;

  try {
    con = DriverManager.getConnection("Jdbc:oracle:thin:@¼­¹öÁÖ¼Ò:PORT:SID","USER","PASSWORD");
    sql =" select imagedata from imageTable where id = '00000' ";
    pstmt = con.prepareStatement(sql);
    rs = pstmt.executeQuery();
    if (rs.next()) {
      input = rs.getBinaryStream("imagedata");
      int byteRead;
      while((byteRead = input.read()) != -1) {
        output.write(byteRead);
      }
      input.close();
    }
  } catch(Exception e) {
    out.print(e);
  } finally {
    try {if (rs != null) rs.close();} catch (Exception ex) {}
    try {if (pstmt != null) pstmt.close();} catch (Exception ex) {}
    try {if (con != null) con.close();} catch (Exception ex) {}
  }
  input.close();
  output.flush();
  output.close();
%>