Originally posted by Stephen Huey:
It seems like a quick and dirty but decent short-term solution could be to just change this to use a PreparedStatement (without any parameters).
This will have zero effect, since it's the parameters that have their quotes (and other special characters) escaped. Unfortunately, you can't just apply the munging to the whole query -- you need to apply it to the parameters individually.
The simplest solution, still using your code above, would be to create a utility method to do the munging and call it from all the places where you call the code above while building the query. This will likely be "good enough" until you can take the time to switch to using prepared statements.