慕哥9229398
如果您希望返回一个游标,那么可以考虑如下所示:SQLiteDatabase db = dbHelper.getWritableDatabase();public Cursor fetchByCountryCode(String strCountryCode){
/**
* SELECT * FROM Country
* WHERE code = US
*/
return cursor = db.query(true,
"Country", /**< Table name. */
null, /**< All the fields that you want the
cursor to contain; null means all.*/
"code=?", /**< WHERE statement without the WHERE clause. */
new String[] { strCountryCode }, /**< Selection arguments. */
null, null, null, null);}/** Fill a cursor with the results. */Cursor c = fetchByCountryCode("US");
/** Retrieve data from the fields. */String strCountryCode = c.getString(cursor.getColumnIndex("code"));
/** Assuming that you have a field/column with the name "country_name"
*/String strCountryName = c.getString(cursor.getColumnIndex("country_name"));看这个片段女笔录以防你想要一个更完整的。请注意,这是一个参数化SQL查询,因此本质上它是一个准备好的语句。