I have the following code.
public static String sqliteSinTilde (String campo)
{
String result = "";
result = " REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LOWER("+campo+"),'á','a'), 'é','e'),'í','i'),'ó','o'),'ú','u'),'Ñ','ñ'),'Á','a'),'É','e'),'Í','i'),'Ó','o'),'Ú','u')" ;
return result;
}
when using this method.. it returns me this.
REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LOWER(DESCRIP),'á','a'), 'é','e'),'Ã','i'),'ó','o'),'ú','u'),'Ã','ñ'),'Ã','a'),'Ã','e'),'Ã','i'),'Ã','o'),'Ã','u')
what am I doing wrong ?
SOLUTION
public static String sqliteSinTilde (String campo)
{
String result = "";
result = " REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(LOWER("+campo+"),'á','a'), 'é','e'),'í','i'),'ó','o'),'ú','u'),'Ñ','ñ'),'Á','a'),'É','e'),'Í','i'),'Ó','o'),'Ú','u')" ;
//String Str2 = "";
String Str3 = "";
try {
//Str2 = new String( result.getBytes( "UTF-8" ));
//System.out.println("Returned Value " + Str2 );
Str3 = new String (result.getBytes( "ISO-8859-1" ));
System.out.println("Returned Value " + Str3 );
} catch ( UnsupportedEncodingException e) {
System.out.println("Unsupported character set");
}
return Str3;
}
You have to have the same encoding in both, but if you don't you'll have to convert the String, use this:
myStringResult is your String,
or if the encoding is the other way around, reverse ISO-8859-1 for UTF-8 or whatever encoding you need.
Greetings.
This is due to differences in charsets between the page and the database. For example, if the base is configured with an ISO-8859-1 charset and the site with a UTF-8 charset, you will get this result.
The solution is to set the same charset settings for both servers (web and database).