Hi all,
I am working on an application where i need to upload a file and store that as a blob column in oracle database. And later on i need to download the same from database to the users machine.
Any input would be highly appreciated!
A snippet of code for your reference!
[CODE]
stmt.execute(" INSERT INTO blob_table (id, file_name) VALUES ("+intId+" ,empty_blob() )");
// Retrieve BLOB locator
strStatement = " SELECT file_name FROM blob_table WHERE id = "+intId+" FOR UPDATE";
resSet = stmt.executeQuery(strStatement);
if (resSet.next()) {
// Get the BLOB locator and open output stream for the BLOB
bFileName = ((oracle.jdbc.driver.OracleResultSet)resSet).getBLOB(1);
blobOutputStream = bFileName.getBinaryOutputStream();
// Open the sample file as a stream for insertion
// into the BLOB column
MultipartRequest multi =new MultipartRequest(request, real_path, 1000 * 1024,
new com.oreilly.servlet.multipart.DefaultFileRenamePolicy());
Enumeration files = multi.getFileNames();
String name = (String)files.nextElement();
File file = multi.getFile(name);
inStream = new FileInputStream(file);
// Buffer to hold chunks of data to being written to the BLOB.
byte[] bBuffer = new byte[bFileName.getBufferSize()*100];
int intBytesRead = 0;
while ((intBytesRead = inStream.read(bBuffer)) != -1) {
// write to BLOB
blobOutputStream.write(bBuffer,0,intBytesRead);
}
// closing the streams and committing
inStream.close();
blobOutputStream.close();
conn.commit();
}
[CODE]