SQliteDatabase 中sql语句引用字符串时的注意点,要把单引号放进去,E/SQLiteLog﹕ (1) no such column:

如下面所示: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


来自为知笔记(Wiz)


你可能感兴趣的:(SQliteDatabase 中sql语句引用字符串时的注意点,要把单引号放进去,E/SQLiteLog﹕ (1) no such column:)