我插入后的主表为foods
的表名为food_id
,该表为integer primary key autoincrement. Now i know that
db.insert()returns id (-1 if insertion failed) but the question is if this is the same id as
food_id ?? i want
food_id`,因为我将食品项保存在列表以及应用程序范围中。
最佳答案
请尝试这个-
//local database variables
private DataSourceUserRecords dataResource ;
private SQLiteDatabase _database = null;
private Cursor _cursor = null;
private MySqliteHelper DBHelper;
将此代码添加到onCreate或您要调用的位置。
DBHelper = new MySqliteHelper(UploadImgService.this);
_database = DBHelper.getWritableDatabase();
dataResource = new DataSourceUserRecords(UploadImgService.this);
dataResource.open();
_cursor = _database.rawQuery("select * from "+MySqliteHelper.TABLE_NAME, null);
_cursor.moveToFirst();
while(_cursor.isAfterLast() == false){
String _food_id = _cursor.getInt(_cursor.getColumnIndex(MySqliteHelper.YOUR_COLUMN_ID));
System.out.println("Food ID from db : " + _food_id );
_cursor.moveToNext();
}
_cursor.close();