I am building an insert command to execute using jdbc. Part of it is to concatenate a user generated string...this all works until the user uses a string like this:
Here's another option:
Use a native Android method designed for exactly this purpose:
DatabaseUtils.sqlEscapeString(String)
Here is the documentation for it online:
The main advantage of using this method, in my opinion, is the self-documentation because of the clear method name.
String userString="a'bcd";
String insertTableSQL = "INSERT INTO myTable "
+ "(insertColumn) "
+ "VALUES("
+"'"+DatabaseUtils.sqlEscapeString(userString)+"'"
+")";
statement.executeUpdate(insertTableSQL);