Save russian in mysql by java

Viewed 111

When I try to execute a query via flyway from my java application, the data in my database are saved in incorrect form. Example is the query below:

INSERT INTO `table_lang` (`id`, `name`) VALUES ('14', 'русский');

The name in table_lang after execution for id= 14 is

p??????

So I thought that the problem was due to the input file, and I tried to insert in the query my name converted with various charsets

  • русский
  • \u0440\u0443\u0441\u0441\u043a\u0438\u0439 as UTF-16
  • \xd1\x80\xd1\x83\xd1\x81\xd1\x81\xd0\xba\xd0\xb8\xd0\xb9 as UTF-8

and I tried to change the charset and the collate of my table of interest respectively

  • CHARACTER SET = utf16 , COLLATE = utf16_general_ci ;

  • CHARACTER SET = utf8 , COLLATE = utf8_general_ci ;

  • CHARACTER SET = utf16 , COLLATE = utf16_general_ci ;

  • CHARACTER SET = utf8mb4 , COLLATE = utf8mb4_general_ci ;

None of these approaches work. Do you know how it can be solved?

2 Answers
  • Use CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

  • You may also need to add characterEncoding=UTF-8 in your JDBC connection string.

With these settings I'm able to write and retrieve Russian and also Turkish charachers on my system.

You may also be interested in How to support full Unicode in MySQL databases

I think the problem is with the server... Which server are you ? I set my global time zone with this command : set global time_zone = '+3:00'; and tried your command : INSERT INTO table_lang (id, name) VALUES ('14', 'русский'); and i got the appropriate output : id name 14 русский Try my command and tell if it works : )

Related