Reputation: 39
I have a table which has a clob datatype column. From my java method, I am trying to update the clob column of a row using update statement. The query is executing without any error, but the clob is not updated. The same code is working for insert statement.
Java Code used for updating clob column:
w_Sql="UPDATE MYTABLE SET MYCLOB= ? WHERE CHANGEREQD = ?";
_pstmt = openConnection().prepareStatement(w_Sql);
Reader reader = new StringReader(clobStr);
_pstmt.setCharacterStream(1, reader, clobStr.length());
Java Code used for inserting clob column:
w_Sql="INSERT INTO MYTABLE VALUES(?,?,?,?,?,?,?,'',?)";
_pstmt = openConnection().prepareStatement(w_Sql);
Reader reader = new StringReader(clobStr);
_pstmt.setCharacterStream(1, reader, clobStr.length());
Please help me understand the issue.
Upvotes: 2
Views: 1696
Reputation: 4647
Answering the question for the others to take advantage, in resolving a situation similar to the OP's question.
setString()
might be useful in the place of setCharacterStream()
Or as an alternate, you might otherwise opt for a solution as suggested on the Oracle documentation altogether!
From the Oracle documentation:
Clob myClob = [CONNECTION OBJECT].createClob();
myClob.setString(1, [actual string value]);
_pstmt.setClob(1, myClob);
Either of the approaches should work and should enable you in updating the CLOB column in your table.
Upvotes: 1