3

I am getting data from my db which contains words in Hebrew. Then I am getting this data from ResultSet putting into a String and then putting it to a JSONObject.

Here is the code:

response.setContentType(application/json);
...
String str = rs.getString['name'];
...
JSONObject obj = new JSONObj();
obj.put("name", str);
...
response.getWriter().write(obj.toString());

Note:

I am using java as my backend and my db is mysql. The db configured to UTF-8

Result:

{"name":"??????"}
vlio20
  • 8,955
  • 18
  • 95
  • 180
  • What character set are you using? – tadman Nov 13 '13 at 19:43
  • DOes EVERYTHING use UTF8? That is: all scripts are saved in UTF8 (the files themselfes!), all network requests use utf8, SQL-transaktions are using UTF8 and, last but not least, your database collation is UTF8? – Johannes H. Nov 13 '13 at 19:47
  • 1
    Where are you seeing this output? A front-end app, a console, etc...it might not be a d/b problem; it might be a display problem (or a problem with the JSON library). – Josh Nov 13 '13 at 19:49
  • The characters are there. The ability of your console device to display them is not. – Bohemian Nov 13 '13 at 19:53
  • @ Space Pope I am making an http request to my back end, I see the output in my browser. Chrome browser. – vlio20 Nov 13 '13 at 19:53
  • 2
    Does the browser actually display UTF8? What is the content-type heder in the HTTP response? – Johannes H. Nov 13 '13 at 19:55
  • For a long time you had to specify the charset in the jdbc connection string for MySQL. You might want to look into that. http://stackoverflow.com/questions/18058297/jdbc-url-for-mysql-configuration-to-use-utf8-character-encoding – Adam Gent Nov 13 '13 at 19:56
  • Solved it with @ Johannes H help. added `response.setCharacterEncoding("utf-8");` – vlio20 Nov 13 '13 at 19:58
  • 1
    Glad I could help. :) Take the credit for the answer yourself, I really only pointed the direction. – Johannes H. Nov 13 '13 at 20:26

1 Answers1

6

Solved it with @ Johannes H help. added response.setCharacterEncoding("utf-8");

vlio20
  • 8,955
  • 18
  • 95
  • 180