escape SQL string - Android java.lang

Android examples for java.lang:String Escape

Description

escape SQL string

Demo Code


public class Main {

  public static String escapeSql(String str) {
    // ' --> ''
    str = str.replaceAll("'", "''");

    // " --> ""
    str = str.replaceAll("\"", "\"\"");

    // \ --> (remove backslashes)
    str = str.replaceAll("\\\\", "");
    return str;//from   w  w  w.  j  ava 2  s. c  om
  }

}

Related Tutorials