A Clob larger that 4K is not stored in the table, only a locator for the 
Clob. That's what getClob returns. You need to get a character stream from 
the locator for either input or output. To do an insert, you normally first 
have to insert the value empty_blob() into the Clob field and then do a 
SELECT ... FOR UPDATE to obtain the Clob, which a locks the row for the 
insert, get the stream and write to it.

Note:

Undocumented Oracle feature: Oracle's Clob and Blob implementation of 
PreparedStatement are inconsistent between the thin driver and the OCI 
driver.  The OCI driver supports using the setCharacterStream() method for 
a Clob and this is the easiest way to write to a Clob. (I.e. you don't need 
to use the locator obtained from a SELECT...FOR UPDATE statement.)

An important gotcha: Oracle's JDBC drivers do not completely implement the 
standard Blob and Clob interfaces. You should instead use Oracle's BLOB and 
CLOB types, which you can obtain from an OracleResultSet with methods the 
getBLOB() and getCLOB(). (Just cast your ResultSet to OracleResultSet to 
call these methods.) BLOB and CLOB have slightly different methods than 
Blob and Clob. Refer to the Oracle doc for details.

Good luck!

- David Gallardo



At 08:09 AM 9/26/2002 -0700, Bo Yang wrote:
>Hello,
>
>A column in a table is defined as CLOB type. I have
>the following code snippet:
>
>String sql = "insert into Statements
>values('7500090000000019',to_date('2002-11-20','YYYY-MM-DD'),?)";
>String clobString = "Some string that is larger than
>4000 chars, in this case it is 5618"; //A real string
>length is 5618
>
>stmt = conn.prepareStatement(sql);
>stmt.setString(1, clobString);
>
>When code gets executed to the above point, it throws
>an Exception as follows:
>
>java.sql.SQLException: Data size bigger than max size
>for this type: 5618
>
>There is a setClob() method for PreparedStatemen as
>follows:
>public void setClob(int i,Clob x)throws SQLException;
>
>However, CLOB is just an interface in JDK.
>
>Could you throw some lights on how to get a CLOB
>object that can set a Java String object? By the way,
>how big a String can hold?
>
>Thanks.
>
>Bo
>
>
>
>
>__________________________________________________
>Do you Yahoo!?
>New DSL Internet Access from SBC & Yahoo!
>http://sbc.yahoo.com
>
>______________________________________________
>To change your JDJList options, please visit:
>http://www.sys-con.com/java/list.cfm


______________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm

Reply via email to