標籤: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亂碼問題