Hi
I'm using MySQL 4.x and the table is configured as EUC-KR characterset.
I cannot change characterset of the DB with my permission.
But I want to store unicode string in the DB.
So, I tried to write string escaper function of my own, like this:
Code:
public static String escape(String str, CharsetEncoder encoder) {
if (str == null) {
return null;
}
int strlen=str.length();
StringBuffer sb = new StringBuffer(strlen*2);
int i;
for (i = 0; i < strlen; ++i) {
char ch = str.charAt(i);
if(encoder.canEncode(ch)) {
sb.append(ch);
}else {
int intValue = ch;
sb.append("&#");
sb.append(intValue);
sb.append(';');
}
}
return sb.toString();
}
and I also wrote unescaper function. but immediately I noticed that I have to MANUALLY escape and unescape the string in EVERY persisted instance.
Is there a smarter method to do this?