Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to insert and retreive zip files in to blob column in oracle database?

843859Jan 10 2006 — edited Oct 26 2007
This is the code to retrieve
while (rs.next() ) {

Blob fileBlobContent = rs.getBlob(1);
String fileName = rs.getString(2);
String value = rs.getString(3);
long fileNum = new Long(value).longValue();

java.io.InputStream is =
((oracle.sql.BLOB) fileBlobContent).getBinaryStream();

FileOutputStream fos =
new FileOutputStream("c:\\temp\\"+fileName);

int c = -1;

while ((c = is.read()) != -1) {
fos.write(c);
}

This is the code to insert into the row aftre inserting empty blob
// step 3 - now put the contents of the file
int length = 0;
int buff_size = 1024;
//Writer out_clob = ((oracle.sql.CLOB)fileCobContent).getCharacterOutputStream();
OutputStream outstream = ((oracle.sql.BLOB) fileBlobContent).getBinaryOutputStream();

long chars_read = data.length();
byte[] buffer = new byte[buff_size];

while ((length+buff_size) < chars_read) {
outstream.write(buffer, length, buff_size);
length += buff_size;
//outstream.flush();
}

// write remaining data
int remaining = (int)(chars_read-length);
outstream.write(buffer, length, remaining);

// steps 4-5:
outstream.flush();

Any help is greatly appreciated. Thanks!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 23 2007
Added on Jan 10 2006
15 comments
2,758 views