I have a scenario with two MySQL databases (in UTF-8), a Java code (a Timer Service) that synchronize both databases (reading form first of them and writing/updating to seco
At some point in the chain, UTF-8–encoded bytes are being decoded with Latin1. From the list of your settings, it appears this is happening at "character_set_server". Without knowing how these values were obtained, it is hard to interpret them.
Check the value of the system property "file.encoding". If that is not "UTF-8", then you need to explicitly specify "UTF-8" as the character encoding whenever you decode bytes to characters. For example, when you call a String
constructor with a byte[]
, or use an InputStreamReader
.
It is best to explicitly specify character encodings, rather than rely on the default platform encoding.
You can set the file.encoding
property of your JVM to UTF-8 so all locale/encoding sensitive API will consider decoded Strings as UTF8.
For example, you can set it in your command line that launches your Java app:
java -Dfile.encoding=UTF-8 ....
You can also refer to this SO question for a complete explanation of Tomcat setup.
A little late but this will help you:
DriverManager.getConnection(
"jdbc:mysql://" + host + "/" + dbName
+ "?useUnicode=true&characterEncoding=UTF-8", user, pass);