[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Write BLOB using EntityManager
|
If you have an object mapped to the table, you could try just reading and
updating the entire blob as a byte[] in the object. If you use the
Oracle9Platform we will stream the blob to get around the 4k size limit.
Otherwise to stream the blob yourself is pretty low-level JDBC, you may need
to continue using JDBC code for this.
Leon Derks-2 wrote:
>
> 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
>
-----
---
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland
http://www.eclipse.org/eclipselink/
EclipseLink , http://www.oracle.com/technology/products/ias/toplink/
TopLink
Wiki: http://wiki.eclipse.org/EclipseLink EclipseLink ,
http://wiki.oracle.com/page/TopLink TopLink
Forums: http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink ,
http://www.nabble.com/EclipseLink-f26430.html EclipseLink
Book: http://en.wikibooks.org/wiki/Java_Persistence Java Persistence
--
View this message in context: http://www.nabble.com/Write-BLOB-using-EntityManager-tp17644674p17649232.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.