Problems reading/writing UTF-8 data in MySQL from Java using JDBC connector 5.1

后端 未结 3 1034
[愿得一人]
[愿得一人] 2020-11-30 09:16

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

3条回答
  •  猫巷女王i
    2020-11-30 09:27

    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.

提交回复
热议问题