Sample Oracle Java program to export BLOB/CLOB to a external file in Oracle 9i -32k
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "EXPORTBLOB" AS
package oracle.apps.cs;
import java.lang.*;
import java.sql.*;
import oracle.sql.*;
import java.io.*;
public class ExportBLOB
{
public static void exportIt(String myDir,String myFile, BLOB myBlob) throws Exception
{
// Bind the object to the database object
// Open streams for the output file and the blob
File binaryFile = new File(myDir,myFile);
FileOutputStream outStream = new FileOutputStream(binaryFile);
InputStream inStream = myBlob.getBinaryStream();
// Get the optimum buffer size and use this to create the read/write buffer
int size = myBlob.getBufferSize();
byte[] buffer = new byte[size];
int length = -1;
// Transfer the data
while ((length = inStream.read(buffer)) != -1)
{
outStream.write(buffer, 0, length);
outStream.flush();
}
// Close everything down
inStream.close();
outStream.close();
}
};
/
No comments:
Post a Comment