java - Replacing single quotes with double quotes in Android database insertion statement -
suppose have execquery statement this:
db1.execsql("insert "+table_name+" values('"name"')"); where name string variable contains apostrophe. example:
name = "tom's database"; in case, sqliteexception near statement. because of single quote.
how modify such statement not cause crash , name stored in db single quote intact?
i read online every such single quote has prefixed single quote.
can provide code same?
escaping special character in string literal works it's error prone approach. it's better use ? placeholder , bind arguments, this:
db1.execsql("insert " + table_name + " values (?)", new string[] { name }); or use insert() contentvalues same.
Comments
Post a Comment