0

In a MySql database I have a column that contains a varchar string encoded with ISO-8859-1 (latin1_swedish_ci).

When the string is not latin1 MySql stores it, for example, as "à¸à¸µà¹à¸à¸."

Using Java I need to extract it and convert it to UTF-8.

Do you know how can I do it?

Thanks

jabal
  • 11,987
  • 12
  • 51
  • 99
user1310165
  • 101
  • 1
  • 2
  • 5
  • 1
    You will need to add more detail on where the string comes from and how you are inserting it. – Pekka Oct 18 '12 at 12:55
  • http://stackoverflow.com/questions/652161/how-do-i-convert-between-iso-8859-1-and-utf-8-in-java – silly Oct 18 '12 at 12:55

1 Answers1

3

Do you mean like ...

byte[] inIso_8859_1 = "à¸à¸µà¹à¸à¸.".getBytes("ISO-8859-1");
byte[] inUtf_8 = new String(inIso_8859_1, "ISO-8859-1").getBytes("UTF-8");

to check the UTF-8 encoding bytes

String s = new String(inUtf_8, "UTF-8");
System.out.println(s);

prints

à¸à¸µà¹à¸à¸.
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130