[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[eclipselink-users] Write BLOB using EntityManager
|
Hello
I have a question, how can I write data to a blob, using the
EntityManager.createNativeQuery("select image_data from image_blobs
where image_id = ? and image_type = ? for update nowait")?
How can I get the stream from the blob?
I used to do this as follows:
PreparedStatement stmt = conn.prepareStatement("select image_data from
image_blobs where image_id = ? and image_type = ? for update nowait");
stmt.setLong(1, image.getId().longValue());
stmt.setString(2, image.getType());
res = (OracleResultSet) stmt.executeQuery();
// get the stream from the blob and let data be streamed into it
if (res.next()) {
BLOB oracleBLOB = res.getBLOB(1);
OutputStream out = oracleBLOB.setBinaryStream(0L);
streamer.stream(out);
out.close();
// now determin the size
res.close();
stmt.close();
stmt = conn.prepareStatement(GET_SIZE);
stmt.setLong(1, image.getId().longValue());
stmt.setString(2, sizeName);
res = (OracleResultSet) stmt.executeQuery();
if (res.next()) {
size = res.getLong(1);
}
}
Leon