表(即疫苗)的結構是:機器人源碼 - 表數據不能被更新
ID-自動增量的主鍵
dose1_date - 串
dose2_date - 串
的DatabaseAccessor
課程如下。從另一個活動調用initDB()
和setVaccineDates
方法。但數據庫沒有更新。但是記錄的消息在logcat中找到。這裏沒有顯示DatabaseHelper
類。
public class DatabaseAccessor {
public static DataBaseHelper myDbHelper = null;
public static SQLiteDatabase rdb = null;
public static SQLiteDatabase wdb = null;
public static synchronized final void initDB(Context context) throws Exception {
if (myDbHelper == null) {
myDbHelper = new DataBaseHelper(context);
myDbHelper.openDataBase();
rdb = myDbHelper.getReadableDatabase();
wdb = myDbHelper.getWritableDatabase();
}
}
public static void setVaccineDates(String birthDate) throws SQLException{
try {
String[] selections = null;
String qry = null;
qry = "select * from vaccines order by id";
Cursor cursor = wdb.rawQuery(qry, selections);
Log.d("update qry===== ", qry);
while (cursor.moveToNext()) {
int rowID = Integer.parseInt(cursor.getString(0));
ContentValues values = new ContentValues();
values.put("dose1_date","66666");
values.put("dose2_date","7777");
wdb.update("vaccines", values, "id=?", new String[] {String.valueOf(rowID)});
//wdb.close();
}
cursor.close();
} catch (Exception e) {
e.printStackTrace();
}
}// end of method setVaccineDates
}
怎麼辦?
編輯:如果我取消了wdb.close()
線,我在logcat中看到
'06 -09 04:21:05.387:W/System.err的(4144):java.lang.IllegalStateException:嘗試重新打開已關閉的對象:SQLiteDatabase:/data/data/com.cloudsoft.vaccine/databases/vaccines2.db '
幫助您觀察應用程序自己的數據庫。顯然bcz關閉後,您試圖在while循環內再次更新。 。 – Bharatesh
你知道你是否正在進入while循環嗎?你的桌子是否填充? –
@DanielK,我說logcat消息是可見的 –