zoukankan      html  css  js  c++  java
  • 解决hibernate向mysql插入中文乱码问题

    1、首先需要修改mysql数据库的配置文件my.ini,此文件放在mysql根目录下。在此文件下查找default-character-set属性,并将其值更改为utf8(注意:不是utf-8,也要注意大小写),这里需要将default-character-set属性全部属性的值修改为utf8。示例:

    default-character-set = utf8

    提示:default-character-set属性有两个,一个在[mysql]下面,另外一个在[mysqld]下面。

    2、同时创建hibernate数据库时需要显示设置数据库的编码方式为utf8。示例:

    create database daycode default charset=utf8;

    3、做完这两步还是不行,需要修改hibernate的配置文件hibernate.cfg.xml,在配置文件配置hibernate.connection.url属性。示例:

    <property name="hibernate.connection.url">
            <![CDATA[jdbc:mysql://localhost:3306/daycode?useUnicode=true&characterEncoding=utf8]]>
    </property>

    注意:此字符串不能写为jdbc:mysql://localhost:3306/daycode?useUnicode=true&characterEncoding=utf8,不然会出现编译错误,错误提示为将&连接符改为;。

    设置这些之后乱码问题就解决了。

  • 相关阅读:
    Qt安装
    Windows下查看进程的工具
    編譯 Boost 1.35.0 (Visual Studio 2005 (VC 8.0) + Windows XP
    boost1.35.0编译日志
    Linux
    Tool
    word cup
    IIS Study
    Oracle PL/SQL语言基础1 [初级] (http://www.cnmpa.com/edu/a1/8/892f4a44496ef382.asp)
    Psychology
  • 原文地址:https://www.cnblogs.com/Blogyin/p/8316543.html
Copyright © 2011-2022 走看看