I receive data from external Microsoft SQL 2008 Data base (I make Queries with MyBatis). In theroy I receive data encoding on "Windows-1252".
I try decoded data with this code:
String textoFormado = ...value from MyBatis... ;
String s = new String(textoFormado.getBytes("Windows-1252"), "UTF-8");
Almost all the String is correctly decoded. But some letter with acents not.
For Example:
- I Receive from Data base this String: "�vila"
- I use the above code and this make this String: "�?vila"
- I expected this String: "Ávila"
Obviously,
textoFormado
is a variable of typeString
. This means that the bytes were already decoded. Java then internally uses a 16-bit Unicode representation. What you did, is to encode your string with Windows-1252 followed by reading the resulting bytes with an UTF-8 encoding. That does not work.What you need is the correct encoding when reading the bytes:
For using this string inside your program, you do not need to do anything. Simply use it. If - however - you want to write the data back to a file for example, you need to encode again:
I solved it thanks to all.
I have the next project structure:
at first I had (MyBatis and Spring inject dependencies and params):
The solution: