0

I have a multi-language Web application written in JavaScript, which approaches a JAVA servlet which it its turn has access to a MySQL database.

Everything appears to work OK except when the language in use is a Semitic one (Arab, Persian, Hebrew) in which case, miraculously, a double-quite character is added at the beginning (or end, depending how you look at it) of the string.

The servlet prints to the console whenever it receives and there, it all looks OK.

When I look at the database, a double-quote character is being added.

So I am inclined to thing that the issue is between the Servlet and MySQL.

This does not happen with any other character set.

Does anyone have any idea why and how to make it work correctly?

Thanks in advance.

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
FDavidov
  • 3,505
  • 6
  • 23
  • 59
  • Weird characters? Check character encodings in the three places. – Aseem Bansal Jun 24 '16 at 17:27
  • No, there are no weird characters but only the addition of a double-quote. This completely damages the JSON that is returned towards the JavaScript. – FDavidov Jun 24 '16 at 18:13
  • I meant unexpected. Check character encodings in the three places. – Aseem Bansal Jun 24 '16 at 18:17
  • utf8 all over the place. The thing is that all is ok with other languages, like German and French (with their special characters). I think it has to do with the fact that Semitic languages are written RTL (as opposed to LTR for English, Spanish, German, ...) . – FDavidov Jun 24 '16 at 18:21
  • I should add that I can see in the Servlet's log that the data going from the JavaScript towards the database is OK, whereas the same data going back from the database towards the JavaScript is polluted with extra double-quotes character (again, only when the strings contain Semitic languages). – FDavidov Jun 24 '16 at 18:30
  • if you are ok with the output from `show create table xyz` on all your tables for RTL in character set (the bottom of the table create / or overrided at the column level inside), then move on to the next layer non db server related – Drew Jun 24 '16 at 18:41
  • what is your servlet container? – Drew Jun 24 '16 at 18:42

1 Answers1

1

It would appear that your answer is here

and this java one with an example:

String unicode= "?useUnicode=yes&characterEncoding=UTF-8";
con = DriverManager.getConnection(url+db+unicode,"root","");

Check also the MySQL manual page entitled Character Sets and Collations Supported by MySQL.

Feel free to downvote this answer. I am happy to delete it too.

Community
  • 1
  • 1
Drew
  • 24,851
  • 10
  • 43
  • 78
  • It looks that setting `default-character-set=utf8` within the my.cnf file made the trick. Still testing, but it looks OK so far. Thanks @Drew for you help. – FDavidov Jun 27 '16 at 09:15