시소당
/* 선언 */
import oracle.sql.*;
import oracle.jdbc.driver.*;
/** 오라클 DB에 BLOB방식으로 파일을 저장한다. */
public void WriteFileDB( ResultSet rs, String rfile, PrintWriter out, String sql, String temppath)
{
try
{
if(rs.next())
{
BLOB blob = ((OracleResultSet)rs).getBLOB(1);
OutputStream blobOutputStream = blob.getBinaryOutputStream();
File file = new File(temppath+rfile);
InputStream in = null;
try {
in = new FileInputStream(file);
byte[] buffer = new byte[10* 1024];
int read = 0; // Number of bytes read
while ((read = in.read(buffer)) != -1) { // Read from file
blobOutputStream.write(buffer, 0, read); // Write to BLOB
}
in.close();
blobOutputStream.close();
file.delete(); //디비에 저장하고 파일을 지운다.
} catch (Exception e) { e.printStackTrace(out); }
finally
{
if(in != null) try{ in.close(); } catch (IOException e) {};
if(blobOutputStream != null) try { blobOutputStream.close();} catch (IOException e) {};
if(file != null) file.delete();
if(blob != null) blob = null;
}
}
} catch (SQLException e) { e.printStackTrace(out); }
finally { }
}
[출처] 파일을 DB(BLOB형)에 쓰기|작성자 젬스
http://blog.naver.com/performed?Redirect=Log&logNo=120011091038