[JAVA] convert File to Blob
자바 java.io.File 객체를 java.sql.Blob 객체로 변환하는 코드.
———-
private Blob convertFileToBlob(File file) throws Exception {
Blob blob = null;
FileInputStream inputStream = null;
try {
byte[] byteArray = new byte[(int) file.length()];
inputStream = new FileInputStream(file);
inputStream.read(byteArray);
blob = new javax.sql.rowset.serial.SerialBlob(byteArray);
} catch (Exception e) {
throw e;
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
} catch (Exception e) {
inputStream = null;
} finally {
inputStream = null;
}
}
return blob;
}