Useful tips : Insert a clob of more than 4k into database
In fact clob are designed to be large objects consisting of characters, so you might be surprise if you try once, with Java JDBC to insert into a database a String of more than 4000 chars... Because the system will crash without telling you any further explanation other than a SQLException. And as a matter of fact 4k char is not exactly what anyone would call a "large object", but the explanation is simple, if you try to insert a tuple into the database using a CLOB directly, if you didn't declare any particuliar behaviour, Oracle will try to store it INLINE (within the same segment) if its size is <4k otherwize the handling is external so you must initialize the tuple with the value EMPTY_CLOB(). The solution to this problem is therefor to do something like this :
// Insert once :
st.executeUpdate("insert into MY_TABLE values(" + id+ "',EMPTY_CLOB())");
// and update :
// using a prepare statement as usual
st.close();
Enjoy !!
Newsletter
Stay updated with new articles.
Keep reading
Useful Tips : How to insert BLOB into an Oracle database using JDBC
It can be quite disturbing to try to insert a BLOB (Binary Large OBject) using JDBC, because most of the time java softwares will handle BLOB, not exactly using their own time, but using Strings. An...
Jun 5, 2009
Useful Tips : StringBuilder and Java String Concatenation
As you certainly now, string concatenation in Java can be achieved using the "+" operator like that : ``` String parText = "This " + "is " + "a full text"; parText = parText + " in a new String objec...
Nov 14, 2009Useful Tips : How to find the biggest files on a unix system ?
Useful mainly when you've got a problem on a unix system because of the space disk. Because some still manage to fill a server with logs or temporary files especially when some programs go nuts and lo...
Jun 3, 2009
No comments yet. Be the first to comment!