How to remove bad characters that are not suitable for utf8 encoding in MySQL?

前端 未结 6 638
刺人心
刺人心 2020-12-16 13:05

I have dirty data. Sometimes it contains characters like this. I use this data to make queries like

WHERE a.address IN (\'mydatahere\')

For

6条回答
  •  -上瘾入骨i
    2020-12-16 13:48

    You can encode and then decode it to/from UTF-8:

    String label = "look into my eyes 〠.〠";
    
    Charset charset = Charset.forName("UTF-8");
    label = charset.decode(charset.encode(label)).toString();
    
    System.out.println(label);
    

    output:

    look into my eyes ?.?
    

    edit: I think this might only work on Java 6.

提交回复
热议问题