UTF-8 conversion error

0

I am converting Strings that I retrieve from the MySql database, however in the database it is saved as UTF-8 to ISO and I am using the code below.

public static String ISO(String str) {
    Charset utf8charset = Charset.forName("UTF-8");
    Charset iso88591charset = Charset.forName("ISO-8859-1");

    ByteBuffer inputBuffer = ByteBuffer.wrap(str.getBytes());

    // decode UTF-8
    CharBuffer data = utf8charset.decode(inputBuffer);

    // encode ISO-8559-1
    ByteBuffer outputBuffer = iso88591charset.encode(data);
    byte[] outputData = outputBuffer.array();

    return new String(outputData);
}

but the capital letter and acute accent as in the word Water is saved on the bank as follows "Water", and in the conversion it does not change, it brings "the water" to the other accents it converts normally.

What can it be?

Does anyone have any idea why only this character does not convert?

    
asked by anonymous 06.09.2016 / 05:12

1 answer

0

This is because the "water" record has already been saved with an unsupported character. In this case, you need to manually tune the database to then convert = /

    
06.09.2016 / 12:50