无法使用getSystemTable和findFirstRow

时间:2016-04-25 06:52:55

标签: java ms-access jackcess

当我尝试使用Jackcess查找需要删除的行以便删除表时,为什么不能使用游标findFirstRow

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

p.s。:没有报告异常

1 个答案:

答案 0 :(得分:0)

您的错误是您要打开要删除的表,而不是包含数据库对象列表的系统表。而不是

Table table = db.getSystemTable(tableName);

你需要使用

Table table = db.getSystemTable("MSysObjects");