0

I use MySQL5.1 with UTF8-encoded for the field customer_name. However, on the JSP-page, which is UTF-8 (in all ways, meta-tags etc), it appears wrong.

In the database I see: "Alѐ"

but on the JSP it renders as: "AlÑ "

which is the same when I query:

select binary(name) from customer where customerID=X;
"AlÑ؀"

Obviously the last char from this query cannot be displayed on the JSP. I cannot determine where this goes wrong. From the resulting RowSet from the query I retrieve the Java-string with plain rs.getString("name"). I've tried setting MySQL variable character_set_connection to utf8 (was latin1), but makes no difference. It must be something really trivial though.

regilero
  • 29,806
  • 6
  • 60
  • 99
  • 1
    have you set names properly? http://stackoverflow.com/questions/2159434/set-names-utf8-in-mysql – nonouco Aug 23 '11 at 12:11
  • I should check if the string goes well from MySQL to Java memory. When you do rs.getString("name") check if theString.codePointAt(2) is equals to 232 (0xE8). – helios Aug 23 '11 at 12:13
  • If it's not, also try normalizing the string (UTF has two ways to represent accented chars): `Normalizer.normalize`. Check http://download.oracle.com/javase/6/docs/api/java/text/Normalizer.html for more info. – helios Aug 23 '11 at 12:14
  • Thank you Helios, the codePointAt(2) results in 209 (the spanish N-tilde). The Normalizer also generates the same spanish N for all 4 decomposition methods. Also I have set names to utf8, no difference. – user907613 Aug 23 '11 at 13:12
  • Whilst debugging more, I found the character is not 232 (0xE8), but actually the cyrillic ie with accent-grave, 0x450 (decimal 1104), which UTF8-to-latin1 results in Ñ <90>. So there is a conversion to Latin1 being done somewhere after all. Must be the database-connection.. – user907613 Aug 23 '11 at 13:29

1 Answers1

0

You've checked that you have utf-8 encoding in database, UTF-8 charset set for the html page and utf-8 set for mysql connection from java, yes?

So the last thing to check, how do you retrieve values from DB? You haven't mentioned any ORM?>

Stepan Vihor
  • 1,069
  • 9
  • 10