In pure JDBC such as servlet, I can insert BLOB to Oracle database. However, in ejb such as SLSB or entity bean, I don't know how to insert blob. One thread suggests using byte array. However in oracle thin driver, setBytes() just supports up to 4000 bytes. If I want to use a stream for blob filed, how do I do it?
In jdbc such as servlet, I am using following code to insert blob to database.
-------------------------------------------------------
In Oracle database, if I want to insert or update LOB, I have to use
Connection.setAutoCommit(false);
ResultSet resultSet = Statement.executeQuery("select ... for update");
Blob blob = resultSet.getBlob();
OutputStream inputStream = blob.getOutputStream();
...
Connection.commit();
--------------------------------------------
How do I implement the above code in ejb because I can not run any setCommit() or commit() in ejb container? If I use UserTransaction.begin() and UserTransaction.commit() to replace setAutoCommit(false) and commit(), it doesn't work.
Jim
-
How to insert blob in ejb (1 messages)
- Posted by: jin xie
- Posted on: April 09 2004 10:38 EDT
Threaded Messages (1)
- How to insert blob in ejb by Senthil Chinnaiyan on April 12 2004 09:44 EDT
-
How to insert blob in ejb[ Go to top ]
- Posted by: Senthil Chinnaiyan
- Posted on: April 12 2004 09:44 EDT
- in response to jin xie
I think you can use CMP Entity Bean. You need to map the BLOB/CLOB type in the container specific descriptor file, the container will take care of the persistance.
For Weblogic:
<field-map>
<cmp-field>photo</cmp-field>
<dbms-column>PICTURE</dbms-column>
<dbms_column-type>OracleBlob</dbms-column-type>
</field-map>
URL: http://edocs.bea.com/wls/docs70/ejb/cmp.html#1061636
For Oc4j:
<entity-deployment name="EmployeePicture" data-source="jdbc/OracleDS" table="EMPPIC">
<primkey-mapping>
<cmp-field-mapping name="empno" persistence-name="EMPNO" persistence-type="NUMBER(8)"/>
</primkey-mapping>
<cmp-field-mapping name="empno" persistence-name="EMPNO" persistence-type="NUMBER(8)"/>
<cmp-field-mapping name="picture" persistence-name="PICTURE" persistence-type="BLOB"/>
</entity-deployment>
</enterprise-beans>
URL: http://otn.oracle.com/tech/java/oc4j/904/how_to/how-to-ejb-cmpblob.zip