hibernate,mysql中文乱码解决方法

来源:互联网 发布:淘宝卖家店铺怎么激活 编辑:程序博客网 时间:2024/06/05 08:15

首先保证整个项目使用统一的编码如gb2312或utf8,在这里我使用的数据库为mysql,安装时设置为utf8编码,gb2312也成,然后在

hibernate.cfg.xml文件中设置你所使用的编码:

    <property name="connection.useUnicode">true</property>
    <property name="connection.characterEncoding">utf8</property>

或在设置数据库连接时采用如:

    <property name="connection.url">jdbc:mysql://localhost:3306/db_group?useUnicode=true&amp;characterEncoding=UTF-8</property>

的方式