6
我有下面的代码来创建我的表。我将数据插入它看起来像这样SQL查询Android的问题Android Where Where子句
_id date recordName total
--------------------------------------
7 2011 TestMaxRecord 5
Java代码:
public static final String KEY_ROWID = "_id";
public static final String KEY_DATE = "date";
public static final String KEY_TOTAL = "total";
public static final String KEY_RECORD_NAME = "recordName";
private static final String DATABASE_CREATE_RECORDS = "create table " + DATABASE_TABLE_RECORDS + " ("
+ KEY_ROWID + " integer primary key autoincrement, "
+ KEY_DATE + " text not null, "
+ KEY_RECORD_NAME + " text not null, "
+ KEY_TOTAL + " text not null);";
public Cursor getRecord(String name) throws SQLException {
return mDb.query(true, DATABASE_TABLE_RECORDS, new String[] {KEY_ROWID, KEY_DATE, KEY_RECORD_NAME, KEY_TOTAL}, KEY_RECORD_NAME + " = " + name, null, null, null, null, null);
}
它每次抛出一个异常,其中name =“TestMaxRecord”(尽管有是在那里的数据),出现以下错误
android.database.sqlite.SQLiteException:没有这样的柱:TestMaxRecord:,在编译:SELECT DISTINCT _id,日期,recordName,总FROM记录WHERE recordName = TestMaxRecord
对我来说,它看起来像是在寻找一个列标题TestMaxRecord
。我是一个android新手,但几乎完全从一个例子中复制这部分(它使用int虽然)。在你的查询中使用int和Strings是否有区别?
是啊,那工作, 谢谢。那是因为它是一个字符串吗?我之前查看过链接中的资源,它对WHERE子句没有帮助。 WHERE子句中的字符串少得多......至少我找到了。 – easycheese