android - 行删除后 SQLite 数据获取问题?

标签 android sqlite

friend ,

我正在尝试删除行,然后当我尝试从数据库中获取所有记录时 我得到异常任何人指导我我在做什么错误?

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;
       }

如有任何帮助,我们将不胜感激。

最佳答案

在调用 selectAll() 之前是否打开了数据库? 你用 delete 方法关闭了它。

无论如何,最好在使用数据库之前打开数据库并在工作完成后关闭它。

关于android - 行删除后 SQLite 数据获取问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5635775/

相关文章:

android - 检查 Android 中的工作互联网连接

java - 如何使用 FirebaseInstanceId.getInstance().deleteInstanceId()?

javascript - 关于如何使用 Phonegap 在 Android 应用程序中捕获屏幕的建议?

javascript - Javascript 有没有办法确定错误是 SQLError?

python - sqlite3 : multiple updates in one transaction

android - Eclipse 找不到 Nexus 4 或 Nexus 7

Android 摄影应用双重曝光

c# - 向 SQLite 表添加列不使用完整的项目名称

django - TypeError:“ModelBase”对象不支持索引。

android - 使用 ORDER BY 在 android sqlite rawQuery 中出现问题?