Java Servlet International Character Encoding UTF-8 with Hibernate and MySQL 中文显示

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

Add following script to your hibernate.cfg.xml file. “useUnicode=true&characterEncoding=utf-8”

 <property name="hibernate.connection.url">jdbc:mysql://localhost/yourschema?autoReconnect=true&amp;useUnicode=true&amp;characterEncoding=utf-8</property>

如果你使用Java Servlet, Mysql和Hibernate, 为了正常显示及存储中文, 可以加入以上脚本

如果显示仍然有问题, 可以尝试使用:

String str="中文测试"; new String(str.getBytes("iso-8859-1"), "utf-8"); 

Read More