简体   繁体   中英

UTF-8 character not supporting

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.

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.

  1. Try

    "update Mutable e set e.Name = '\Б\л\а\г\\u43e\C4\а\р\я'";

    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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM