Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

problem with Blob data

  Asked By: Anpu    Date: Apr 01    Category: Java    Views: 951
  

I had problem with Blob data ,

I have uploaded zip file to oracle database ,
can u please send me the solution how to retrieve the data and save
it into disk using ZipOutputStream.

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Freda Lane     Answered On: Apr 01

some code from net
.
.
.

try {
Statement stmt = connection.createStatement();
ResultSet rs = stmt.executeQuery("SELECT col_blob FROM
mysql_all_table");

if (rs.next()) {
// Get the blob  from the result set
Blob blob = rs.getBlob("col_blob");

// Get the number bytes in the BLOB
long blobLength = blob.length();

// Get bytes from the BLOB in a byte array
int pos = 1; // position is 1-based
int len = 10;
byte[] bytes = blob.getBytes(pos, len);

// Get bytes from the BLOB using a stream
InputStream is = blob.getBinaryStream();
int b = is.read();
}
} catch (IOException e) {
} catch (SQLException e) {
}


and this is another code from net


// Create the decompressor and give it the data  to compress
Inflater decompressor = new Inflater();
decompressor.setInput(compressedData);

// Create an expandable byte array to hold the decompressed data
ByteArrayOutputStream bos = new
ByteArrayOutputStream(compressedData.length);

// Decompress the data
byte[] buf = new byte[1024];
while (!decompressor.finished()) {
try {
int count = decompressor.inflate(buf);
bos.write(buf, 0, count);
} catch (DataFormatException e) {
}
}
try {
bos.close();
} catch (IOException e) {
}

// Get the decompressed data
byte[] decompressedData = bos.toByteArray();




so the only thing u 'll have to do to find out how to write a file  using java.
and then make little optimizations on your code... : )

 
Answer #2    Answered By: Hooriya Khan     Answered On: Apr 01

u have to do the following things :
>first of all select the row from oracle  db.
>then get the BLOB from resultset(use orcle BLOB interface plz don't use
java.sql.Blob
> now open a input stream from BLOB (u can find it in BLOB interface)
>now read from the input stream and write it to a local file  system or u can use
this input stream for zipinputstream.

thats it.

 
Didn't find what you were looking for? Find more on problem with Blob data Or get search suggestion and latest updates.




Tagged: