I have a String of more than 5000 characters, which I want to save as XMLTYPE with MyBatis. For this I do the following:
convert the String to CLOB and the CLOB use it to save it in database with the constructor: XMLTYPE.CREATEXML.
I have a problem when converting the String to CLOB.
If I do it in the first way, the CLOB object that is created is a SerialClob has 3 fields: BUF, LENG and CLOB; but of these three fields only two are filled: BUF (buffer) and LENG but CLOB is null.
But if I do it in the second way, I create the complete CLOB object, with all the String, and I do not have problems saving it in the database. But the first way I create a SerialClob, which does not allow it to be saved in an XMLTYPE.
I can not use the XMLTYPE constructor with VARCHARS because my String has more than 4000 characters.
Is there an alternative without having to open a connection?
Clob myClobFile;
String str = "<myString example></end of example>";
First way:
try
{
myClobFile= new javax.sql.rowset.serial.SerialClob (str.toCharArray ());
}
Second way:
try
{
myClobFile= sqlSession.getConnection ().createClob ();
myClobFile.setString (1, str);
}