Topic:
I encountered a strange bug in the code released today. Everything is normal on my computer. I use a local database. It can also run normally when transplanted to the target computer. However, there is a table that cannot query data and report exceptions.
debugging:
1. Run the system, enter Chinese in the settings, and find that it returns garbled characters, guessing that it is a problem of garbled characters
2. Check the database code: show variables like '%char%'; found that there is latin1 code, modify it to utf8mb4, restart the database, restart the program, still abnormal. (set character_set_result=utf8mb4;)
3. Check the database configuration connection: jdbc:mysql://39.106.157.61:3306/schmsite, the encoding is not specified, so modify it to: jdbc:mysql://39.106.157.61:3306/schmsite?useUnicode=true&characterEncoding=utf8
4. The operation is normal.
When dealing with databases in the future, you must first ensure that the encoding format is correct. Remember to remember that it is a waste of time, and it is a problem that has been encountered before.
Paste the code as follows:
show VARIABLES like '%char%'; set character_set_client = utf8mb4; set character_set_connection = utf8mb4; set character_set_database = utf8mb4; set character_set_results = utf8mb4; set character_set_server = utf8mb4;