본문 바로가기

DataBase/Oracle SQL

[ORACLE] LONG ROW TYPE


컬럼 Type 중에  CLOB, BLOB, LONG, VARCHAR2 , INT 등등 여러가지 타입이 있지만,

이번에 프로젝트 하면서 LONG ROW 란 컬럼을 보았다,

보통 LONG ROW 는 안에 파일만 첨부되어 있고 그 첨부파일을 다운받는 용도로 사용되는 첨부파일에 해당하는 컬럼 타입이 LONG ROW  였다. (말이 뭐 쫌 꼬이는 감이 없지 않아 있군..  - -)

CLOB 과 비슷하게.. 파싱해서 사용한다.


 public void handleResultSet(ResultSet rs) {
  ok = false;
  ServletOutputStream os = null;
  InputStream is = null;
  try {
   if( rs.next()) {
    String filename = rs.getString(1);
    is = rs.getBinaryStream(2);
    if( filename.endsWith(".hwp")) {
     response.setHeader("Content-Type", "application/x-hwp");
    } else {
     response.setHeader("Content-Type", "application/octet-stream; charset=euc-kr");
    }
   
    // 다운로드시 한글이 깨지는 문제가 발생하여 Encoding하는 부분 변경
    response.setHeader("Content-Disposition", "attachment; filename=" + new String(filename.getBytes("EUC-KR"), "8859_1") + ";");

    os = response.getOutputStream();
    int bytesRead;
    byte[] buffer = new byte[1024*32];
    if( is!=null) {
    // fullpath에 있는 파일을 Byte로 읽어서 OutputStream에 Write한다
     while (( bytesRead = is.read( buffer)) != -1) {
      os.write(buffer, 0,  bytesRead );
     }
    }
    
      ok = true;
   } else {
    DAO.logger.debug("파일이 없습니다");
   }
  } catch (Exception e) {
   DAO.logger.error(e);
   ok=false;
  } finally {
   if(is != null ) { try { is.close(); } catch (IOException e) {  } }
   if(os != null ) { try { os.close(); } catch (IOException e) {  } }
  }
 }

이번 프로젝트에서 쓰였던 DaoFileHandler.java   파일! 참고~


'DataBase > Oracle SQL' 카테고리의 다른 글

[Oracle] ORACLE JOIN  (0) 2010.11.16
[SQL] 제약조건 삭제  (0) 2010.08.24
[ORACLE] CASE WHEN ~ THEN ~ ELSE END  (3) 2010.04.20
[Procedure] UDF oracle function 프로시져 create 예제  (0) 2010.03.08
[ORACLE] instr() 함수  (0) 2010.02.22