无法使用 getSystemTable 和 findFirstRow 通过 Jackcess 删除 table
Unable to drop table via Jackcess using getSystemTable and findFirstRow
当我尝试使用 Jackcess 查找我需要删除的行以删除 table 时,为什么不能游标 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.: 没有报告异常
您的错误是您打开的是要删除的 table,而不是保存数据库对象列表的系统 table。而不是
Table table = db.getSystemTable(tableName);
你需要使用
Table table = db.getSystemTable("MSysObjects");
当我尝试使用 Jackcess 查找我需要删除的行以删除 table 时,为什么不能游标 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.: 没有报告异常
您的错误是您打开的是要删除的 table,而不是保存数据库对象列表的系统 table。而不是
Table table = db.getSystemTable(tableName);
你需要使用
Table table = db.getSystemTable("MSysObjects");