【发布时间】:2016-03-12 01:16:51
【问题描述】:
我正在尝试从表中获取值。
cursor=db.rawQuery("select value from '" + tableName + "' where key= '" + name + "' ",null);
if (cursor.getCount()>0){
if (cursor.moveToFirst()){
String value= cursor.getString(cursor.getColumnIndex("value"));
return value;
}
cursor.close();
}
我得到了例外:
Couldn't read row 0, col -1 from Cursor Window.Make sure cursor is initialised correctly before accessing data from it.
当我使用时:
cursor.getString(0);
我能够得到我需要的价值。
如果我使用,
cursor.getString(cursor.getColumnIndex("value"));
我得到了例外。
【问题讨论】:
-
你的变量 tableName 为空。
-
sry....我发布了错误的错误...我更新了问题@GabeSechan
-
是命名值还是值? SQL 对表名和列名区分大小写,即使它不用于关键字。
-
总而言之-不要使用字符串追加查询这样的值。将变量附加到 SQL 文本是要求 SQL 注入错误。请改用绑定变量。
-
然后getColumnIndex("VALUE");
标签: android sqlite android-cursor