id-自动增量主键
dose1_date - string
dose2_date - string
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 /数据库/ vaccines2.db '
答案 0 :(得分:0)
As a newbie in android it was just a mistake out of ignorance that this situation took place: after update
operation I tried to find the changes in the database file (i.e. file with .db
extension sitting inside assets
folder in Eclipse) through sqlite browser。但实际发生的是在设备中运行的应用程序(真实的或模拟器)有自己的数据库,该数据库是从.db
文件夹内的assets
扩展文件创建的,随后的数据库操作只影响应用程序&#39 ; s自己的数据库不会触及Eclipse中提到的文件夹内的数据库。还有一种方法可以在Eclipse的文件资源管理器'中运行设备中观看应用程序自己的数据库。 (在DDMS模式下)借助Questoid SQlite Manager