0

Why can't cursor findFirstRow when I try to use Jackcess to find the row that I need to delete in order to drop a table?

private static void deleteTable(Database db, String tableName) throws IOException {
    Table table = db.getSystemTable(tableName);
    if (table == null) {
        return;
    }
    Cursor cursor = table.getDefaultCursor();
    Map<String, Object> criteria = new HashMap<String, Object>();
    criteria.put("Name", tableName);
    criteria.put("Type", (short) 1);
    if (cursor.findFirstRow(criteria)) {
        table.deleteRow(cursor.getCurrentRow());
        Log.e(TAG, "delete " + tableName + "   success!");
    } else {
        Log.e(TAG, "can't find this Table");//run here
    }
    db.flush();
    db.close();
}
PS.: no reported exception
BugKiller
  • 94
  • 1
  • 10
  • A title should succinctly describe the problem; use the body of the question to explain the problem in more detail. If that means repeating the title in the body, then repeat the title. Questions with only code in the body are usually low quality. – Mark Rotteveel Apr 25 '16 at 07:58

1 Answers1

0

Your mistake is that you are opening the table you want to delete, not the system table that holds the list of database objects. Instead of

Table table = db.getSystemTable(tableName);

you need to use

Table table = db.getSystemTable("MSysObjects");
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418