on 06-10-2008 1:25 PM
Hi all,
I'm sending a JDBC record to a file but I'm wondering how I can send a BLOB (Binary large object) to a file.
Can anyone advise me how I can write such a file (eg a JPEG file) on a directory?
Thanks in advance!
Regards,
Wouter.
Hello,
Yes it is possible to do using the Java mapping .You need to do XI Binary Conversion to process it.
Use this link for Step by Step procedures.
hope this will solve your requirement.
*************Rewarad points,if found useful
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I have found some java code that should help me write a BLOB column to a OS file:
/**
* Method used to write the contents (data) from an Oracle BLOB column to
* an O/S file. This method uses one of two ways to get data from the BLOB
* column - namely the getBytes() method. The other way to read data from an
* Oracle BLOB column is to use Streams.
*
* @throws java.io.IOException
* @throws java.sql.SQLException
*/
// public void readBLOBToFileGet()
// throws IOException, SQLException {
Connection conn = null;
String outputBinaryFileName1 = null;
File outputBinaryFile1 = null;
FileOutputStream outputFileOutputStream = null;
String sqlText = null;
Statement stmt = null;
ResultSet rset = null;
BLOB image = null;
long blobLength;
long position;
int chunkSize;
byte[] binaryBuffer;
int bytesRead = 0;
int bytesWritten = 0;
int totbytesRead = 0;
int totbytesWritten = 0;
try {
stmt = conn.createStatement();
outputBinaryFile1 = new File(outputBinaryFileName1);
outputFileOutputStream = new FileOutputStream(outputBinaryFile1);
sqlText =
"SELECT image " +
"FROM test_blob " +
"WHERE id = 1 " +
"FOR UPDATE";
rset = stmt.executeQuery(sqlText);
rset.next();
image = ((OracleResultSet) rset).getBLOB("image");
blobLength = image.length();
chunkSize = image.getChunkSize();
binaryBuffer = new byte[chunkSize];
for (position = 1; position <= blobLength; position += chunkSize) {
// Loop through while reading a chunk of data from the BLOB
// column using the getBytes() method. This data will be stored
// in a temporary buffer that will be written to disk.
bytesRead = image.getBytes(position, chunkSize, binaryBuffer);
// Now write the buffer to disk.
outputFileOutputStream.write(binaryBuffer, 0, bytesRead);
totbytesRead += bytesRead;
totbytesWritten += bytesRead;
}
outputFileOutputStream.close();
conn.commit();
rset.close();
stmt.close();
System.out.println(
"==========================================================\n" +
" GET METHOD\n" +
"==========================================================\n" +
"Wrote BLOB column data to file " + outputBinaryFile1.getName() + ".\n" +
totbytesRead + " bytes read.\n" +
totbytesWritten + " bytes written.\n"
);
} catch (IOException e) {
System.out.println("Caught I/O Exception: (Write BLOB value to file - Get Method).");
e.printStackTrace();
throw e;
} catch (SQLException e) {
System.out.println("Caught SQL Exception: (Write BLOB value to file - Get Method).");
System.out.println("SQL:\n" + sqlText);
e.printStackTrace();
throw e;
}
//}
But how I should import the package in order to use the BLOB datatype?
Thx already for your help!
Regards,
Wouter.
HI,
Have refer the link to process the image file with XI, this will help you in this scenario
Thanks
swarup
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.