Reputation: 4180
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?
Upvotes: 3
Views: 5858
Reputation: 1062
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.
Upvotes: 0
Reputation: 2861
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
Upvotes: 3
Reputation: 18945
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.
Upvotes: 1