Link to home
Start Free TrialLog in
Avatar of mruff
mruff

asked on

DB2 store CLOB from java bigger then 32KB

Dear experts,

We have a table with a CLOB:
LARGE_TEXT_FIELD CLOB(262144)
Now if we want to store a string bigger then 32KB from our java application via the db2 jdbc driver we get the error:

 sqlcode: -102

 sqlstate: 54002
*

The DB2 server runs on linux, is version DB2 LUW 9.5

The same occurs if I e.g. want issue an sql insert via WinSQL which connects via ODBC to the DB2 server
How can this issue be solved?
We want to be able to store strings greater then 32KB
Storing a string smaller then 32KB works fine

*One of the following has occurred:
*  The comment in the COMMENT ON statement is greater than 254 bytes.
*  The application server name specified in the SQL CONNECT statement is
   greater than 18 bytes.
*  The string constant beginning with "<string>" has a length greater
   than 32672 bytes. Character strings with lengths greater than 32672
   bytes or graphic strings with lengths greater than 16336 characters
   can be specified only through assignment from host variables. Note
   that other servers in the DB2 family of products may specify a
   different size limit for character strings. Consult the documentation
   for the appropriate DB2 product for details.
*  In an XQuery expression, a string literal beginning with "<string>"
   has a length greater than 32672 bytes. The limit is determined on the
   string literal encoded in UTF-8. A string with length greater than
   32672 bytes can only be specified in an XQuery expression using XML
   values from the database through the XQuery functions that access
   data or through an XQuery variable assigned a value using SQL/XML
   functions like XMLQUERY, XMLEXISTS, or XMLTABLE.
*  Federated system users: the data source-specific limits must not be
   exceeded in a pass-through session. For example, a character literal
   larger than 254 bytes included in a statement sent to DB2 for OS/390
   in a pass-through session would cause this error.

It may be that data conversion is occurring and the resultant string is
too long. For connections between applications and databases running
under different codepages, string constants are converted from the
application codepage to the database codepage. In certain situations,
graphic string constants may be further converted from the database
codepage to a UCS-2 (UNICODE) encoding, for example when the database
has been created with an EUC codepage. This means that it is possible to
have a resultant string which is longer than the input string.

The statement cannot be processed.

User response:

For Comment on Table or Comment on Column, reduce the size of the
comment. For the SQL CONNECT statement, reduce the length of the
application server name. For other string constants, the requested
function is not available interactively. For an error occurring in the
context of a non-CONNECT SQL statement embedded in an application
program, assign the long string to a host variable and substitute that
variable for the string literal in the SQL statement.

Federated system users: for a pass-through session, determine what data
source is causing the error (see the Troubleshooting Guide for the
failing data sources). Examine the SQL dialect for that data source to
determine which specific limit has been exceeded, and adjust the failing
statement as needed.
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or, more simply, you might try

preparedStatement.setCharacterStream(3, new StringReader(myString));

Open in new window

Avatar of mruff
mruff

ASKER

Great!
Thx yes using a prepared statement solved the problem
Many thanks
Not a problem, glad to help!