0

I faced utf8 character encoding problem with Java. I read database data 'ঊনত্রিশ' but with java it shows 'ঊনত�?রিশ'. Below my processes

  1. My Filter request.setCharacterEncoding("UTF-8");
  2. MySQL Connection String is:
    jdbc:mysql://localhost:3306?useUnicode=true&characterEncoding=UTF-8
  3. model.name = resultSet.getString("name");
  4. byte[] utf8JsonString = model.name.getBytes(StandardCharsets.UTF_8);
    model.name = new String(utf8JsonString);

I don't know where my faults are.

Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
Bipul Roy
  • 100
  • 6
  • 14
  • 1
    `model.name = new String(utf8JsonString);` you're not specifying the charset, so you're using your JVM's default. (Although it's unclear why you convert string to `byte[]` to string). – Andy Turner Sep 12 '18 at 14:57
  • 1
    Why are you converting `model.name` to bytes and back? – Thomas Sep 12 '18 at 14:57
  • Has your database correct [UTF-8 settings](https://stackoverflow.com/questions/3513773/change-mysql-default-character-set-to-utf-8-in-my-cnf)? If you go there by using your favourite client [tool](https://www.eversql.com/top-5-mysql-gui-tools-for-windows/) you see your data with correct encoding? – m4gic Sep 12 '18 at 15:31
  • @m4gic I test it with node.js & php and output is correct (same database) – Bipul Roy Sep 12 '18 at 15:49

0 Answers0