Search code examples
javapostgresqlquotes

Inserting string with single quotes from Java into Postgresql


I'm inserting text from a Java application into a Postgresql database, but it all crashes when a ' char is encountered in the String. I've tried using replaceAll(" ' ", " \\' "); even diffrent variants of it with more \ chars, yet it still puts a single ' in the String without the escape sign.

Is there any way of replacing the ' with an \' in the String? Or another way of putting Strings containig single quotes into Postgresql?


Solution

  • You shouldn't have to worry about doing this manually if you're using prepared statements properly.