Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
michael byrd
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael,
Sorry if I'm missing the obvious, but what is the problem when you run the above code?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic