你還為資料庫亂碼煩惱嗎?,資料庫亂碼煩惱

來源:互聯網
上載者:User

你還為資料庫亂碼煩惱嗎?,資料庫亂碼煩惱

1、首先需要修改mysql資料庫的設定檔my.ini,

此檔案放在mysql根目錄下。在此檔案下尋找default-character-set屬性,並將其值更改為utf8(注意:不是utf-8,也要注意大小寫),這裡需要將default-character-set屬性全部屬性的值修改為utf8。樣本:

default-character-set = utf8


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,不然會出現編譯錯誤,錯誤提示為將&串連符改為;。


設定這些之後亂碼問題就解決了。


相關文章

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.