Data insertion, deletion, and other operations are often used in projects. Sometimes the data returned by the server is enclosed in Chinese single quotes. Therefore, direct insertion reports a syntax error. There are two solutions:
First:
Replace all single quotes
String Regexp = "\'";
String deletesql = "delete from"
+ Dbconstants. db_table.table_history + "where"
+ Dbconstants. History. history_keyword + "= '"
+ Keyword. replaceall (Regexp ,"")
+ "'";
Second
Converts Chinese single quotes into English single quotes, which are more user-friendly.
String deletesql = "delete from"
+ Dbconstants. db_table.table_history + "where"
+ Dbconstants. History. history_keyword + "= '"
+ Keyword. replaceall (Regexp, "'") + "'";
It's just a little trick. Haha
String RegEx = "['~! @ # $ % ^ & * () + =|{} ':;', // [//]. <> /?~! @ # ¥ % ...... & * () -- + | {} [] ';: "'., ,?] "; In this case, all characters can be filtered out.