Resolve the problem of Hibernate + MySQL Chinese scrambled code

  • 2020-04-01 02:05:30
  • OfStack

If it is a Windows system, then the default local character set of the system is gb2312, in order to make the data table also use gb2312 character set, we need to write the SQL statement to create the data table:

CREATE TABLE TEST
{
 ...
 ...
 ...
}default character set gb2312;

Then add the following to hibernate.cfg.xml:

<property name="connection.characterEncoding">gb2312</property> 

If it's a Linux system, just change the gb2312 above to UTF8.

Related articles: