android sqlite - table 数据无法更新
android sqlite - table data cannot be updated
table(即疫苗)结构是:
id-自增主键
dose1_date - 字符串
dose2_date - 字符串
DatabaseAccessor
class如下。 initDB()
和 setVaccineDates
方法是从另一个 activity 调用的。但是数据库没有更新。但是,在 logcat 中可以找到记录的消息。 DatabaseHelper
class 此处未显示。
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
}
怎么办?
Edit :如果我取消注释 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
'
作为android的新手,发生这种情况只是出于无知的错误:在update
操作之后,我试图找到数据库文件中的更改(即带有.db
扩展位于 Eclipse 中的 assets
文件夹内)通过 sqlite browser . But what actually happens is the app running in the device (real one or emulator) has its own database which is created from the .db
extension file inside assets
folder and consequent database operations only affect the app's own database leaving no touch on the database inside the mentioned folder in Eclipse. And there is the way to watch the app's very own database in the running device in Eclipse's 'File Explorer' (in DDMS mode) with the help of Questoid SQlite Manager
table(即疫苗)结构是:
id-自增主键
dose1_date - 字符串
dose2_date - 字符串
DatabaseAccessor
class如下。 initDB()
和 setVaccineDates
方法是从另一个 activity 调用的。但是数据库没有更新。但是,在 logcat 中可以找到记录的消息。 DatabaseHelper
class 此处未显示。
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
}
怎么办?
Edit :如果我取消注释 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 '
作为android的新手,发生这种情况只是出于无知的错误:在update
操作之后,我试图找到数据库文件中的更改(即带有.db
扩展位于 Eclipse 中的 assets
文件夹内)通过 sqlite browser . But what actually happens is the app running in the device (real one or emulator) has its own database which is created from the .db
extension file inside assets
folder and consequent database operations only affect the app's own database leaving no touch on the database inside the mentioned folder in Eclipse. And there is the way to watch the app's very own database in the running device in Eclipse's 'File Explorer' (in DDMS mode) with the help of Questoid SQlite Manager