Hi Andy, Erik,

we have a lot of derby errors "ERROR 22001: A truncation error was encountered trying to shrink CHAR 'XXX' to length 1."

I analysed the problem writing a little Java program that uses JDBC directly. The program inserts a row into a table having a single CHAR(1) column. The program uses a prepared statement and binds a Java character to it using different methods:

1) PreparedStatement.setShort
2) PreparedStatement.setInt
3) PreparedStatement.setObject
4) PreparedStatement.setString

Note: There is no PreparedStatement.setChar. The program runs with different Java characters:

If the Java character is greater or equal 0xA, then 1), 2), 3) fail.
If the Java character is less than 0xA and greater or equal 0x0, then only 3) fails.

When 1) and 2) fails, then the exception message is the same as above. 3) always fails with "An attempt was made to get a data value of type 'CHAR' from a data value of type 'java.lang.Character'." (I do not understand this message). 4) is always sucessfull.

It seems that 1) and 2) fail, because Derby stores numbers in string representation if the database column type is CHAR, e.g 0xA => "10".

So, I wonder if JPOX uses 1) or 2) when binding a single character? This would be an explanation for 25 error messages. Can you please check that? I think the right method to use is 4).

Regards,
Michael
--
-------------------------------------------------------------------
Michael Watzek                  [EMAIL PROTECTED] Engineering GmbH
mailto:[EMAIL PROTECTED]        Buelowstr. 66
Tel.:  ++49/30/235 520 36       10783 Berlin - Germany
Fax.:  ++49/30/217 520 12       http://www.spree.de/
-------------------------------------------------------------------

Reply via email to