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

Enjoy !!


Votre commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:


Vous commentez à l’aide de votre compte Déconnexion /  Changer )

Photo Facebook

Vous commentez à l’aide de votre compte Facebook. Déconnexion /  Changer )

Connexion à %s

%d blogueurs aiment cette page :