database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
PostgreSQL
Firebird
Oracle
Informix
Sybase
MS-SQL
ㆍDB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
DB2 Q&A 1559 게시물 읽기
No. 1559
BLOB형 소스보고 틀린곳좀 알려주세요
작성자
이남식
작성일
2008-03-13 09:31ⓒ
2008-03-13 10:08ⓜ
조회수
9,309

아래와 같이 BLOB형을 업로드/다운로드 받고 있습니다...
어디가 잘못된것인지 좀 알려주세요.....
해결방안도 알려주신다면 감사하겠습니다....


인서트는 어떻게 되긴 합니다....
(OutputSteream 부분이 에러나서 뺐더니 입력이 안되네요...-_-;;)
다운로드가 안되고요....
일부만 되는줄 알았는데요 찾아보니
어떤경로로 들어가게 됐는지는 모르겠지만 
C:\tomcat\bin 안에 업로드한 몇개의 파일이 있었고 
이곳에 있는 파일들만 다운로드가 됐었습니다.

새로 파일 내용을 수정하여 업로드를 하여도(톰캣빈 안에 있는 파일말고)
톰캣빈안에 있는 파일을 읽어 왔습니다. 
톰캣빈안에 있는 파일을 수정하면 새로 업로드 안하더라도 수정이 되어있고요

인서트가 잘 안된것이거나 
다운로드창을 잘못 만든것이 아닌가 싶은데요 
벌써 BLOB로 헤맨것이 두자리수가 넘어섰네요....


=====================
== BLOB 인서트  =====
=====================

 public int insertFile(HttpServletRequest request) throws SQLException{

  int iResult = 0;
  DBManager objDBManager = null;

  Connection con = DBModules.DBConnection();
  con.setAutoCommit(false);
  PreparedStatement ps;
  ResultSet rs = null;

  int iFileId = 0;
  int iFileBoardId = 0;
  int insertResult = 0;
  int iCount = 0;
  
  String strSQL = "";
  String strTitle = "";
  String strContents = "";
  String strEmpId = "";
  String strName = null;

  File FileData = null;
  FileInputStream fin = null;
  OutputStream os;
  
  byte[] buffer = null;
  
  try{
   objDBManager = new DBManager();
   objDBManager.OpenDatabase();
   
   iFileBoardId = Util.getNewNumber();
   iFileId = Util.getNewNumber();
   strEmpId = request.getParameter("EmpId");
   strTitle = Util.toKor(request.getParameter("Title"));
   strContents = Util.toKor(request.getParameter("Contents"));
   FileData = new File(Util.toKor(request.getParameter("DATA")));
   strName = FileData.getName();
   String strDir = FileData.getParent();
   fin = new FileInputStream(FileData);
 
   
   strTitle = strTitle.replace("<", "<");
   strContents = strContents.replace("<", "<");
   strContents = strContents.replace(" ", " ");
   strContents = strContents.replace("\n", "
");
    
   strSQL = " INSERT INTO WEB_FILEBOARD(BOARDID, EMPID, TITLE, CONTENTS, REGDT) ";
   strSQL += " VALUES (?,?,?,?,CURRENT TIMESTAMP) ";
   
   ps = con.prepareStatement(strSQL);
   ps.setInt(1,iFileBoardId);
   ps.setString(2, strEmpId);
   ps.setString(3, strTitle);
   ps.setString(4, strContents);
   ps.executeUpdate();

   ps.close();
   ps = null;
   
   strSQL = " INSERT INTO WEB_FILE(FILEID, BOARDID, NAME, DATA, REGDT) ";
   strSQL += " VALUES (?,?,?,NULL,CURRENT TIMESTAMP) ";

   ps = con.prepareStatement(strSQL);
   ps.setInt(1,iFileId);
   ps.setInt(2,iFileBoardId);
   ps.setString(3, strName);

   ps.executeUpdate();
    
   ps.close();
   ps = null;
 
   strSQL = " SELECT DATA FROM WEB_FILE WHERE FILEID = ? FOR UPDATE ";
   
   
    ps = con.prepareStatement(strSQL);
    ps.setInt(1, iFileId);
    rs = ps.executeQuery();    
  
  if(rs.next()){

     fin = new FileInputStream(FileData);
     buffer = new byte[1*1024*1024];
     Blob blobData = rs.getBlob(1);
                   
                     //os = blobData.setBinaryStream(0);         nullpointerException 발생함


     while(true){

      iCount = fin.read(buffer);
      if(iCount == -1){
       break;
      }

                     //os.write(buffer);                                   nullpointerException 발생함


     }
     fin.close();
    }
   con.commit();
  
  }catch(Exception e){
   e.printStackTrace();
   Util.insertErrorMessage(e);
  }finally{
   if (objDBManager.getDBStatus()){objDBManager.CloseDatabase();}
   objDBManager.closeDBManager();
   objDBManager = null;
   
   con.close();
  }
  
  return iResult;
 } 

이 글에 대한 댓글이 총 1건 있습니다.

======================
== BLOB DOWNLOAD  =
======================

<%@ page contentType="text/html; charset=euc-kr" %>



<%@ page import="java.io.*"%>
<%@ page import="infra.framework.common.Util" %>
<%
        String filename = Util.toKor(request.getParameter("file_name"));
        String filename2 = new String(filename.getBytes("euc-kr"),"8859_1");
        File file = new File(filename); // 절대경로입니다.
        byte b[] = new byte[(int)file.length()];
        response.setHeader("Content-Disposition", "attachment;filename=" + filename2 + ";");
        if (file.isFile())
        {
                    BufferedInputStream fin = new BufferedInputStream(new FileInputStream(file));
                    BufferedOutputStream outs = new BufferedOutputStream(response.getOutputStream());
                    int read = 0;
                    while ((read = fin.read(b)) != -1){
                                outs.write(b,0,read);
                    }
                    outs.close();
                    fin.close();
        }
%>

이남식님이 2008-03-13 09:37에 작성한 댓글입니다. Edit
[Top]
No.
제목
작성자
작성일
조회
1564DECLARE NOT_FOUND CONDITION FOR '02000' ; [1]
런던
2008-03-19
9548
1563BLOB 업로드시 로컬에서 되서 서버에서 안되는 이유?? [5]
이남식
2008-03-18
9745
1560버전이 다른 두 DB간 연계 [1]
DB2
2008-03-13
9384
1559BLOB형 소스보고 틀린곳좀 알려주세요 [1]
이남식
2008-03-13
9309
1558blob 업로드 파일 수정후 업로드/다운로드시 내용 수정안되는 현상 [1]
이남식
2008-03-12
8604
1557물어볼것이 있습니다. [2]
한준호
2008-03-12
9019
1556blob 입출력에 관해서 안되는거 몇개 질문이요 [2]
이남식
2008-03-11
8696
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.019초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다