friends,
i am trying to delete row and then when i try to fetch all records from database
i get exception any one guide me what mistake am i doing?
private static final String DATABASE_NAME = "example.db";
private static final int DATABASE_VERSION = 1;
private static final String TABLE_NAME = "table1";
private Context context;
private SQLiteDatabase db;
public dbHelper(Context context) {
this.context = context;
OpenHelper openHelper = new OpenHelper(this.context);
this.db = openHelper.getWritableDatabase();
this.insertStmt = this.db.compileStatement(INSERT);
}
public List<String> selectAll() {
List<String> list = new ArrayList<String>();
Cursor cursor = this.db.query(TABLE_NAME, new String[] { "name" },
null, null, null, null, "name desc");
if (cursor.moveToFirst()) {
do {
list.add(cursor.getString(0));
} while (cursor.moveToNext());
}
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
return list;
}
public int DeleteName(String name)
{
int rowsEffected = this.db.delete(TABLE_NAME,"name=?", new String[] {name});
this.db.close();
return rowsEffected;
}
any help would be appreciated.
Have you opened db before call selectAll()?
You closed it in delete method.
Anyway it is good practice to open db before work with it and close it after the work is done.