0

I can insert data to my database with this:

mydb.execSQL("INSERT INTO " + TABLE_NAME + " (NAME, CITY) VALUES 
('John','Toronto')");

But if I use the parameter as fallow for CITY, my application crashes:

String str2="Toronto";
mydb.execSQL("INSERT INTO " + TABLE_NAME + " (NAME, CITY) VALUES 
('John',str2)");

why?

1 Answers1

0
String str2='Toronto';

Try using single quotations otherwise execSQL will assume your query ends at the double quotes.

This may help explain insert string using sqlite in android containing single and double quotes in it