• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
author & internet detective
Posts: 42055
926
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Michael,
Sorry if I'm missing the obvious, but what is the problem when you run the above code?
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic