<form id="hz9zz"></form>
  • <form id="hz9zz"></form>

      <nobr id="hz9zz"></nobr>

      <form id="hz9zz"></form>

    1. 明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

      Java 中文問題的處理

      [摘要]Java 中文問題一直困擾許多學習者?偨Y了下面的一些情況的解決方法。希望對大家有幫助。連接 Mysql Database Server:------------------------------------------------------------------------------- ...
      Java 中文問題一直困擾許多學習者?偨Y了下面的一些情況的解決方法。
      希望對大家有幫助。

      連接 Mysql Database Server:
      -------------------------------------------------------------------------------
      mysql 不支持 unicode,所以比較麻煩。
      將 connectionString 設置成 encoding 為 gb2312
      String connectionString
      = "jdbc:mysql://localhost/test?useUnicode=true&characterEncoding=gb2312";

      測試代碼:
      String str = "漢字";
      PreparedStatement pStmt = conn.prepareStatement("INSERT INTO test VALUES (?)";
      pStmt.setString(1,str);
      pStmt.executeUpdate();

      數據庫表格:
      create table test (
      name char(10)



      連接 Oracle Database Server
      -------------------------------------------------------------------------------
      在把漢字字符串插入數據庫前做如下轉換操作:
      String(str.getBytes("ISO8859_1","gb2312"

      測試代碼:
      String str = "漢字";
      PreparedStatement pStmt = conn.prepareStatement("INSERT INTO test VALUES (?)";
      pStmt.setString(1,new String(str.getBytes("ISO8859_1","gb2312";
      pStmt.executeUpdate();


      Servlet
      -------------------------------------------------------------------------------
      在 Servlet 開頭加上兩句話:
      response.setContentType("text/html;charset=UTF-8";
      request.setCharacterEncoding("UTF-8";

      JSP
      -------------------------------------------------------------------------------
      在 JSP 開頭加上:
      <%@ page contentType="text/html; charset=gb2312" %>



      日韩精品一区二区三区高清