You can escape a single quote by repeating it:
term.replaceAll("'","''");
An even better option would be a parameterized query. For an example, we'd have to know your client language.