Search code examples
javaoracle11gclob

CLOB in oracle not allowing to insert data more than 4000 chars


Below is my table

create table MY_LOG(SQNO NUMBER, CLOB_FLD CLOB);

Below is my insert statement executed from java side

stmt.execute(new StringBuilder(
                "INSERT INTO MY_LOG VALUES ('").append(logMessage.getNo()).append("','").append(logMessage.getStackTrace()).append("')"));

the stacktrace is too large i.e more than 4000 characters. So Its throwing

SQL Error: ORA-01704: string literal too long
01704. 00000 -  "string literal too long"
*Cause:    The string literal is longer than 4000 characters.
*Action:   Use a string literal of at most 4000 characters.
           Longer values may only be entered using bind variables.

Is there any function or procedure inbuilt or is there anything i can do to make this work properly ??

Thanks in advance..


Solution

  • Use PreparedStatement, create a CLob with Connection.createCLob, put your text into CLob with CLob.setString, set PreparedStatement parameter with PreparedStatement.setCLob