I have a database with MEDIUMBLOB fields in tables with ENGINE=InnoDB DEFAULT CHARSET=utf8 on each table.
I connect to the database with useUnicode=true&characterEncoding=UTF8&character_set_client=UTF8&character_set_database=UTF8&character_set_results=UTF8&character_set_server=UTF8&character_set_system=UTF8 on the URL.
(I have tried with just useUnicode=true&characterEncoding=UTF8 with the same results.)
When I look at values in the database using mysql from the command-line, I can see non-ASCII characters just fine.
But when I read in strings from the database using executeQuery() getString() I get gibberish. How can I read in the values correctly?
I am using log4j to show the strings I am writing to the database, and those I read back, and those I write show fine.
That’s a BLOB, not a string. So you want
getBytesand decode it manually.If you want more transparent support, defined a mediumtext column with UTF-8. Then all that configuration will become effective and you get proper strings automatically with getString.