You will not only encounter this situation in Hibernate, but also in mainstream php. If your database encoding is different from the page encoding, chinese garbled characters may occur.
You will not only encounter this situation in Hibernate, but also in mainstream php. If your database encoding is different from the page encoding, chinese garbled characters may occur.
Today, we encountered garbled characters when using Hibernate to insert data into MySQL. During the specific performance, I used UTF-8 to print Chinese characters before insertion, then set MySQL Workbench to uft-8 to display the data queried from MySQL is also correct, but when I insert the data in the code and then query it is garbled, I don't know how to set it. Because there is no problem with UTF-8 at both ends, the problem must be in the middle, that is, connect. The search results are found everywhere on the Internet.
We only need to set it in the hibernate. property Or hibernate. cfg. xml (depending on how you connect to the database) file.
My connection statement was originally written as follows:
The Code is as follows: |
|
Jdbc: // localhost: 3306/tablename |
Then I changed it:
The Code is as follows: |
|
Jdbc: mysql: // localhost: 3306/tablename? UseUnicode = true & characterEncoding = utf8 |
I found that it still does not work. I used to change it to this:
The Code is as follows: |
|
</p><p>jdbc:mysql://localhost:3306/tablename?useUnicode=true&characterEncoding=utf8</p><p> |