zoukankan      html  css  js  c++  java
  • 解决hibernate向mysql插入中文乱码问题(更改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,不然会出现编译错误,错误提示为将&连接符改为;。
     
    设置这些之后乱码问题就解决了。
    --------------------------------以下为在wamp中设置Mysql字符的方法----------------------------------------------------
    打开my.ini
    [client]下添加:default-character-set=utf8
    [wampmysqld]下添加:
    character_set_server=utf8

    init_connect='SET NAMES utf8'

    保存,重启即可

  • 相关阅读:
    wxWidgets教程
    Unity游戏资源反解工具
    The Story About .NET Cross Platform UI Frameworks
    IMGUI
    Unity可编程管线的顶点光照Shader
    常用mac命令
    Vulkan相关资源
    Controlling fixed function states from materials/scripts in Unity
    Forward Rendering VS Deferred Rendering
    C#转PHP
  • 原文地址:https://www.cnblogs.com/jiafuwei/p/4423101.html
Copyright © 2011-2022 走看看