MySQL亂碼問題

來源:互聯網
上載者:User

標籤:etc   中文   one   user   manage   insert   exec   exe   drive   

 JSP的request 預設為ISO8859_1,所以在處理中文的時候,  要顯示中文的話,必須轉成GBK的,如下  String str=new String(request.getParameter("name").getBytes("ISO8859-1"),"GBK");  out.println(str);  這樣就可以顯示中文了  MYSQL操作時的中文問題:  這個要看MySQL的預設編碼了,一般不調整的話為latin1其實和ISO8859_1一樣,所以操作的時候要處理  和他一致,不然就會亂碼的  1.插入中文:  String sql2="INSERT INTO test (name) VALUES(‘"+request.getParameter("name")+"‘)";  stmt.executeUpdate(sql2);  不用編碼就可以插入了  2.顯示插入的中文:  因為存入的是latin,所以顯示的時候就要GBK一下  String x=new String((rs.getString("title")).getBytes("ISO8859_1"),"GBK");  out.println(x);  3.設定儲存編碼:  當然在MySQL為latin1編碼時,也可以存的時候用GBK了  Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/jsp?  useUnicode=true&characterEncoding=GBK","root","");  str1="中文";  String sql2="INSERT INTO test (name) VALUES(‘"+str1+"‘)";  這樣也可以很成功的插入   http://user.qzone.qq.com/372806800/blog/1336199262

 

MySQL亂碼問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.