Article Image
read

While in the process of upgrading our connector/J to version 5.1 we started seeing the following error:

ComplexByteArrayException: ByteArray objects cannot be converted to strings.

After doing a little homework we found that the root cause was in the way that CONCAT() processed numbers. CONCAT() was returning a binary string due to having both numbers and strings as arguments.

Our fix was to CAST() all numbers to CHAR, which results in a normal string being returned. Another option is to call toString() on all of your affected columns when referencing them in the query object.

For example the SQL fix is demonstrated below:

Select Concat('a string', 1)

would return a binary string where as

Select Concat('a string', Cast(1 as char))

would return a "normal" string.

Resources:

  1. http://bugs.mysql.com/bug.php?id=7739
  2. http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat
  3. http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date
  4. http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format
Blog Logo

Jon Dowdle

Jon Dowdle currently works on the internet at a lovely place called InVision.


Published

Color

Jon Dowdle's Blog

The personal blog of Jon Dowdle.

Back to Overview