Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save russian in mysql by java

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?

like image 876
Jonio Avatar asked Mar 22 '26 02:03

Jonio


1 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

like image 102
fantaghirocco Avatar answered Mar 24 '26 16:03

fantaghirocco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!