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