I am internationalizing my web application using resource files with UTF-8 encoding. My properties file for Chinese language looks like this
logincomment = \u767B\u5F55\u5230
swissues = \u4F60\u6709\u95EE\u9898\u6216\u4E0E\u7684\u95EE\u9898\u5417\uFF1F
buassign = \u60A8\u5F53\u524D\u672A\u5206\u914D\u7ED9\u4E1A\u52A1\u90E8\u95E8\u3002\u8BF7\u8054\u7CFB\u60A8\u7684\u7EC4\u7EC7\u7684\u5E10\u6237\u5C06\u88AB\u5206\u914D\u7684\u7BA1\u7406\u5458\u3002
visitour = \u5C1D\u8BD5\u8BBF\u95EE\u6211\u4EEC
faq = \u5E38\u89C1\u95EE\u9898
strt= \u4E00\u4E2A\u4F1F\u5927\u7684\u5730\u65B9\u5F00\u59CB \uFF01
q1 = \u60F3\u77E5\u9053\u66F4\u591A\u5173\u4E8E\u8FD9\u4E2A\u5F53\u524D\u7684 SMARTWaste \u7248\u672C\u5417\uFF1F\u627E\u51FA\u66F4\u591A\u7684\u6211\u4EEC
releasenote = \u53D1\u884C\u8BF4\u660E
This displays Chinese text correctly on my web pages.
For this to work I also had to change the following line on my JSP page
<%@page contentType="text/html; charset=iso-8859-1" pageEncoding="iso-8859-1"%>
to
<%@ page contentType="text/html; charset=utf-8" pageEncoding="UTF-8" %>
But this has caused me another problem.
Before I changed the <% page %>
tag, when Chinese characters were saved through this application to the database, it used to convert it ASCII codes. For example the text "废物和环境报告工具" was being converted automatically to "废 物 和 环 境 报 告 工 具" and then saved to the database.(I removed ; from the ASCII codes so that it won't show in Chinese)
After changing the <% page %>
tag, it is now saving "废物和环境报告工具" as "åº?ç?©å??ç?¯å¢?æ?¥å??å·¥å?·"
When I display the saved text on the webpage,
<%="废 物 和 环 境 报 告 工 具"%>
shows 废物和环境报告工具.
But <%="åº?ç?©å??ç?¯å¢?æ?¥å??å·¥å?·"%>
shows åº?ç?©å??ç?¯å¢?æ?¥å??å·¥å?·
My JDBC connection string is jdbc:jtds:sqlserver://servername/db_name;useUnicode=true;characterEncoding=UTF-8
What is the best way I can store and display Chinese characters in the database?
Thanks Cris
EDIT:
Following is the printed out insert query just before running it from the application
INSERT INTO [TestTranslation]
([RecordContent], [RecordDescription])
VALUES (N'ä»?ç??æ?©äº?座æ??å«?ç´?å?¨å¹´é??æ??å??ç?¹å?¤å¾?ã??', N'ä»?ç??æ?©äº?座æ??å«?ç´?å?¨å¹´é??æ??å??ç?¹å?¤å¾?ã??')
This query is run by the JSP application when I type in 今生悩予座朝嫌紙周年際提児点古征。in the [RecordContent] field and 今生悩予座朝嫌紙周年際提児点古征。in the [RecordDescription] field on the online form.
Changing this query to
INSERT INTO [TestTranslation]
([RecordContent], [RecordDescription])
VALUES (N'今生悩予座朝嫌紙周年際提児点古征。', N'今生悩予座朝嫌紙周年際提児点古征。')
will fix the issue, but I don't know how to make the java application put the Chinese text instead of the encoding in the query.
The code which constructs this query is
String query = "INSERT INTO [TestTranslation] ([RecordContent], [RecordDescription])";
query += " VALUES (N'" + request.getParameter("recordContent") + "', N'" + request.getParameter("recordDescription") + "')";
db.update(query);