Hi,
I would advice upgrading to 2.4.x. We use our own BlobManager code that loads database
specific code to handle LOB data. After trying out different approaches this seemed to
be the best solution at the time. This is the code we use to read and write (B)LOBs
with the oracle thin driver:
<code>
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.InputStream;
import java.sql.Blob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import oracle.sql.BLOB;
public class OracleBlobManager extends AbstractBlobManager {
/*
That method works fine but it's using oracle.sql.Blob because it provides
the getBinayOutputStream().
*/
public void createBlob(Connection conn, Long id, byte[] blob)
throws BlobProcessingException {
try {
/* 2. insert empty_blob() locator */
PreparedStatement pstmtInsert = conn.prepareStatement(
"INSERT INTO " + this.tableName + " VALUES (?,EMPTY_BLOB())");
pstmtInsert.setLong(1, id.longValue());
pstmtInsert.executeUpdate();
pstmtInsert.close();
/* 3. get inserted locator */
Statement stmtInsert=conn.createStatement();
ResultSet rsInsert = stmtInsert.executeQuery(
"SELECT blob_id FROM " + this.tableName
+ " WHERE ID=" + id + " FOR UPDATE");
rsInsert.next();
BLOB myBlob = (BLOB)rsInsert.getBlob(1);
/* 4. update the blob */
OutputStream newstreamOut = myBlob.getBinaryOutputStream(); // method provided
by oracle.BLOB
newstreamOut.write(blob);
newstreamOut.flush();
newstreamOut.close();
stmtInsert.close();
} catch (SQLException e) {
// TEMPORARY OUTPUT
e.printStackTrace();
throw new BlobProcessingException("SQL problems with database",e);
} catch (IOException e) {
// TEMPORARY OUTPUT
e.printStackTrace();
throw new BlobProcessingException("I/O problems with database",e);
}
}
public void updateBlob(Connection conn, Long id, byte[] blob)
throws BlobProcessingException, BlobNotFoundException {
try {
/* 2. get inserted locator */
Statement stmtUpdate=conn.createStatement();
ResultSet rsUpdate = stmtUpdate.executeQuery(
"SELECT blob_id FROM " + this.tableName
+ " WHERE ID=" + id + " FOR UPDATE");
if (rsUpdate.next()) {
BLOB myBlob = (BLOB)rsUpdate.getBlob(1);
/* 3. update the blob */
OutputStream newstreamOut = myBlob.getBinaryOutputStream(); // method
provided by oracle.BLOB
newstreamOut.write(blob);
newstreamOut.flush();
newstreamOut.close();
} else
throw new BlobNotFoundException("Blob manager update failed. "
+ "Row ID not found.");
stmtUpdate.close();
stmtUpdate = null;
} catch (SQLException e) {
throw new BlobProcessingException("SQL problems with database",e);
} catch (IOException e) {
throw new BlobProcessingException("I/O problems with blob",e);
}
}
byte[] getObject(ResultSet rs)
throws ClassNotFoundException,SQLException,IOException {
Blob b = rs.getBlob("blob_id");
return b.getBytes( 1L, (int) b.length() );
}
}
</code>
Note that we use oracle specific code. This code is part of a framwork, all the stuff
you are missing is standard to all database so you should be able to figure it out for
yourself.
Hope this helps.
Joost.
_______________________________________________________________
Don't miss the 2002 Sprint PCS Application Developer's Conference
August 25-28 in Las Vegas -- http://devcon.sprintpcs.com/adp/index.cfm
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development