0

I am trying to add row in database as follows:

String query = "update Mutable e set e.Name = "Благодаря";
Statement s;
s.execute(query);

But it updates as ?????? in database. I am setting this name to a Russian string. But if i run same query in MySQL query browser then it updates the name correctly. I am not able to find the reason.

M A
  • 71,713
  • 13
  • 134
  • 174
Pratik
  • 109
  • 1
  • 5
  • 14

2 Answers2

1

This issue is resolved. The problem was in my.cnf file. in the my.cnf file the default character set was latin1. which i changed to UTF8 and it worked.

Pratik
  • 109
  • 1
  • 5
  • 14
0
  1. Try

    "update Mutable e set e.Name = '\u0411\u043b\u0430\u0433\u43e\u00434\u0430\u0440\u044f'";

    This u-escaping to ASCII removes one problem: that the encoding of the java source text must be the same as the encoding used by the javac compiler.

  2. Then easily the results can be displayed false in a Windows or IDE console with a non-Cyrillic encoding. Check the results in the database, as you did.

    You can check the value indirect:

    System.out.println("Okay: " + !fieldValue.contains("?"));
    
  3. Verify that the connection string is something like:

    "jdbc:mysql:///dbname?useUnicode=true&characterEncoding=utf-8"
    

    which ensures that the driver communication uses UTF-8.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • I tried this. But when i type this line then the eclipse editor throws Error "Invalid Unicode". – Pratik Sep 09 '14 at 13:57
  • @Pratik all unicode should be 4 digits, not 3 or 5. BTW once the code is compiled they shouldn't make any difference. – Peter Lawrey Sep 09 '14 at 14:05
  • This issue is resolved. The problem was in my.cnf file. in the my.cnf file the default character set was latin1. which i changed to UTF8 and it worked. – Pratik Sep 16 '14 at 09:16