//oracle db public static void writeToFile (BLOB b) throws Exception {

int chunk = b.getChunkSize();
byte[] buffer = new byte[chunk];
int length;

FileOutputStream outFile = null;
outFile = new FileOutputStream("out.jpg");
InputStream instream = b.getBinaryStream();

// Fetch data

while ((length = instream.read(buffer)) != -1) {
outFile.write(buffer, 0, length);
}

// Close input and output streams
instream.close();
outFile.close();
}