com.ibm.db2.jcc.am.SqlException: [jcc][10120][11936][4.14.88] Invalid operation: Lob is closed. ERRORCODE=-4470, SQLSTATE=null

StackOverflow https://stackoverflow.com/questions/22360721

  •  13-06-2023
  •  | 
  •  

Question

In our application we are having a simple POJO class that has a Clob attribute within it.

I am having issue in getting the String representation of that Clob entity.

Say I have already queried and cached the result in the POJO object, now I am trying to get the String value of the Clob as below.

int aLength = (int)myPojo.getClobField().length();
String aStringValue = myPojo.getClobField().getSubString(1L, aLength);

But the above execution gives me the error,

com.ibm.db2.jcc.am.SqlException: [jcc][10120][11936][4.14.88] Invalid operation: Lob is closed. ERRORCODE=-4470, SQLSTATE=null

Am I missing something?

Was it helpful?

Solution 2

The Clob Java object is not a copy of the CLOB value stored in the database. It is a locator (pointer), which becomes invalid after the result set is closed. You'll need to copy CLOB contents while processing the result set.

OTHER TIPS

This issue can be solved by adding progressiveStreaming=2; argument to the connection url

The fully specified Connection URL is to be given as below:

jdbc:db2://localhost:50000/SAMPLE:progressiveStreaming=2;

In case you have exception on that parameter add the following to it or add any one or combinations of these parameters to fix it:

jdbc:db2://localhost:50000/SAMPLE:driverType=4;fullyMaterializeLobData=true;fullyMaterializeInputStreams=true;progressiveStreaming=2;progresssiveLocators=2;

It is preferred to use db2jcc4.jar

For hibernate users , when mapping to a database Lob type (BLOB or CLOB) the field should be annotated @Lob and no need to keep the copy , you can directely convert it in to character array like

(java.sql.Clob)payload.field1 bodyText = clobTest.getCharacterStream() 
 targetString = org.apache.commons.io.IOUtils.toString(bodyText) 
int length=targetString.length();
payload.PAYLOADHEADERS=targetString
return payload

Make sure you have added progressiveStreaming=2; in your data-source configuration properties.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top