Java web後台插入資料庫中文亂碼問題解決

來源:互聯網
上載者:User

標籤:prot   ogr   csdn   client   out   dir   eclipse   介面   protocol   

前言:項目想要避免亂碼情況的出現,要保持伺服器、資料庫、項目、以及前端編碼一致。
一、項目以及前端編碼,設定。

myeclipse--->右鍵項目--->Properties--->Resource--->Text file encoding----->選擇utf-8---->apply--->ok

 

二、tomcat6.x伺服器編碼設定

D:\apache-tomcat-6.0.37\conf\server.xml,

[html] view plain copy
  1. <Connector port="8080" protocol="HTTP/1.1"   
  2.              connectionTimeout="20000"   
  3.              redirectPort="8443"  URIEncoding="UTF-8"/>  
[html] view plain copy
  1. <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8"/>  


後面的URIEncoding="UTF-8"就是所添加進去的內容

 

三、資料庫MySQL5.5設定;

①先開啟 運行--->cmd--->net stop MySQL  關閉mysql的服務

②C:\Program Files (x86)\MySQL\MySQL Server 5.5\my.ini

修改如下四個欄位為

[html] view plain copy
  1. [client]  
  2. port = 3306   
  3. default-character-set=utf8   
[html] view plain copy
  1. [mysql]  
  2. default-character-set=utf8  
[html] view plain copy
  1. [mysqld]  
  2.   
  3. character-set-server=utf8   
  4. port = 3306   
[html] view plain copy
  1. character-set-server=utf8  

儲存。

③開啟 運行--->cmd--->net start mysql  開啟MySQL的服務
④開啟MySQL的命令列介面,輸入密碼進入後

執行 show variables like ‘character%‘;該語句,顯示如下即表示設定成功


Java web後台插入資料庫中文亂碼問題解決

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.