Hibernate of solutions to Chinese problems

Source: Internet
Author: User

See a solution for Hibernate+mysql Chinese problem on the Internet, as follows

System configuration: Win2k3 server,jsdk 1.5.0 rc,mysql 4.0.20a,hibernate 2.1.0, Elcipse 3.0.1
Problem Description: In the use of hibernate as a data persistence layer solution, we will encounter Chinese problems, when the specific situation of the Chinese characters inserted into the database display as???
Explore: After the test found that encoding related to the following two places, one is the database connection URL, one is programmed to get the configuration class instance of the way the statement.
Programme 1:
* The statement that gets the instance of the configuration class when programming is
* New Configuration (). addclass (Xx.class);
You must add the URL after the database is connected to the Hibernate.properties file. Characterencoding=gbk&useunicode=true
Programme 2:
* The statement that gets the instance of the configuration class when programming is
* New Configuration (). Configure ().
Set in the <session-factory/> block of a hibernate.cfg.xml file
<property name= "Connection.useunicode" >true</property>
<property name= "Connection.characterencoding" >UTF-8</property>
or write when programming:
Properties Extraproperties = new properties ();
Extraproperties.put ("Hibernate.connection.useUnicode", "true");
Extraproperties.put ("hibernate.connection.characterEncoding", "UTF-8");
Myconfiguration.addproperties (extraproperties);

But my son. In Hibernate3.1+mysql5, you must set both the parameters and the <property> properties of the URL, otherwise you cannot store Chinese properly

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.