如何删除不适合MySQL中utf8编码的错误字符? [英] How to remove bad characters that are not suitable for utf8 encoding in MySQL?
本文介绍了如何删除不适合MySQL中utf8编码的错误字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有脏数据。有时它包含这个字符。我使用这些数据进行查询,如
I have dirty data. Sometimes it contains characters like this. I use this data to make queries like
WHERE a.address IN ('mydatahere')
对于这个角色我得到
org。 hibernate.exception.GenericJDBCException:操作'IN'的非法混合排序(utf8_bin,IMPLICIT),(utf8mb4_general_ci,COERCIBLE),(utf8mb4_general_ci,COERCIBLE)
org.hibernate.exception.GenericJDBCException: Illegal mix of collations (utf8_bin,IMPLICIT), (utf8mb4_general_ci,COERCIBLE), (utf8mb4_general_ci,COERCIBLE) for operation ' IN '
如何过滤掉这样的字符?我使用Java。
How can I filter out characters like this? I use Java.
谢谢。
推荐答案
可能会这样帮助某人,因为它帮助了我。
May be this will help someone as it helped me.
public static String removeBadChars(String s) {
if (s == null) return null;
StringBuilder sb = new StringBuilder();
for(int i=0;i<s.length();i++){
if (Character.isHighSurrogate(s.charAt(i))) continue;
sb.append(s.charAt(i));
}
return sb.toString();
}
这篇关于如何删除不适合MySQL中utf8编码的错误字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文