Data common character encoding problem handling

Sometimes the visual tools we use to operate the database are all set to utf-8 when the database is newly created, but in actual operation, when inserting data into the table, garbled characters are often inserted. At this time, you can try to connect to the database. The specific function of adding useUnicode=true&characterEncoding=utf-8 to the url of the configuration file is as follows. The

added function is: specify the encoding and decoding format of characters.

             For example: the mysql database uses gbk encoding, while the project database uses utf-8 encoding. At this time, if useUnicode=true&characterEncoding=UTF-8 is added, then the function has the following two aspects:

1. When storing data: when the

     database stores project data, it will first decode the data into bytecode in UTF-8 format, and then The decoded bytecode is then stored in the database using GBK encoding again.

2. When fetching data:

     When fetching data from the database, the database will first decode the data in the database into bytecodes in GBK format, and then re-encode the data in UTF-8 format after decoding the bytecodes. Finally, the data is returned to the client.

Note: When configuring the database utl in the xml configuration file, the escape character of & is &

      for example: <property name="url" value="jdbc:mysql://localhost:3306/email?useUnicode=true& ;characterEncoding=UTF-8" />

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326735297&siteId=291194637