如下面所示:name是string型的,这样直接引用会出现错误提示:
android.database.sqlite.SQLiteException: no such column: longman (code 1): , while compiling: insert into demo (name,age) values(longman,55)
public void insertData(String name, int age) { db.execSQL("insert into demo (name,age) values("+name+","+age+")"); }
修改方法,把单引号放到双引号里面去,也就是当name变成你传入的值的时候,sql语句对string类型的变量就能有双引号功能了:如图绿色所示
public void insertData(String name, int age) { db.execSQL("insert into demo (name,age) values(‘"+name+"‘,"+age+")"); }
来源: http://write.blog.csdn.net/postedit/50533170
时间: 2024-11-08 02:55:26