Today in the use of hibernate to MySQL insert data in the garbled problem, the specific performance when I utf-8 in the insertion of the Chinese when the OK, and then use the MySQL Workbench set to Uft-8 to show the data from the MySQL query is also correct, But when I put the data in the code into the database and then query when the query came out is garbled, do not know how to set up, because two utf-8 are no problem, the problem is certainly out in the middle, that is, connect the time. Find the results on the Internet.
All we need to do is set the Hibernate.property or Hibernate.cfg.xml (depending on how you connect to the database) in the file to make it OK.
Originally my connection statement was written:
The code is as follows |
Copy Code |
<property name= "Connection.url" > Jdbc:mysql://localhost:3306/tablename </property> |
And then I changed it:
The code is as follows |
Copy Code |
<property name= "Connection.url" > Jdbc:mysql://localhost:3306/tablename?useunicode=true&characterencoding=utf8 </property> |
Find or not, the original is to change to this:
code is as follows |
copy code |
< Property name= "Connection.url" <![ cdata[ Jdbc:mysql://localhost:3306/tablename?useunicode=true&characterencoding=utf8 ]]> </property> |