我想将结果限制为KEY_HOMEID等于journalId的结果.我已经在这几天了,任何帮助将不胜感激.
public Cursor fetchAllNotes(String journalId)
{
return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_HEIGHT,
KEY_BODY, KEY_HOMEID},"FROM DATABASE_TABLE WHERE KEY_HOMEID = journalId",null, null, null, null,null);
}
看看http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#query
您的查询应该看起来像这样:
mDb.query(DATABASE_TABLE, // Table name columnNames, // String[] containing your column names KEY_HOMEID+" = "+jounalId, // your where statement, you do not include the WHERE or the FROM DATABASE_TABLE parts of the query, null, null, null, null );
如果您对编写SQL查询感觉更舒服,您还可以使用:
mDb.rawQuery("SQL STATEMENT", null);
如果你在参数(在查询参数中)使用它,它会使你的代码更清晰示例:
String [] settingsProjection = { DBContract.Settings._ID, DBContract.Settings.COLUMN_NAME_USER_ID, DBContract.Settings.COLUMN_NAME_AUTO_LOGIN }; String whereClause = DBContract.Settings.COLUMN_NAME_USER_ID+"=?"; String [] whereArgs = {userId.toString()}; Cursor c = db.query( DBContract.Settings.TABLE_NAME, settingsProjection, whereClause, whereArgs, null, null, null );