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();
}
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");