user1310165
user1310165

Reputation: 101

Convert MySql string ISO-8859-1 to UTF-8 with Java

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

Upvotes: 0

Views: 3445

Answers (1)

Peter Lawrey
Peter Lawrey

Reputation: 533680

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

à¸à¸µà¹à¸à¸.

Upvotes: 3

Related Questions