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

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -