Mercurial > hg > monetdb-java
view src/main/java/nl/cwi/monetdb/embedded/utils/StringEscaper.java @ 42:dfea8468cd1a embedded
Finished Java code for CRUD operations on tables and the documentation.
author | Pedro Ferreira <pedro.ferreira@monetdbsolutions.com> |
---|---|
date | Tue, 08 Nov 2016 14:57:26 +0100 (2016-11-08) |
parents | |
children |
line wrap: on
line source
package nl.cwi.monetdb.embedded.utils; /** * An util class to escape Java Strings to avoid SQL Injection and other problems with SQL queries. * * @author <a href="mailto:pedro.ferreira@monetdbsolutions.com">Pedro Ferreira</a> */ public class StringEscaper { /** * Escapes a Java String for usage in SQL queries. * * @param input The String to escape * @return The input String escaped */ public static String SQLStringEscape(String input) { return "'" + input.replaceAll("\\\\", "\\\\\\\\").replaceAll("'", "\\\\'") + "'"; } }