如何使用 Jackcess 删除 (DROP) 访问表



我在我的项目中使用Jackcess来连接MS Access数据库,但我找不到删除表的方法。

如何使用杰克塞斯删除表?

Database db = null;
try 
{
    db = Database.open(FileLocations.getCache());
    Table table = db.getTable("refNum");
    //table.delete(); //trying to achieve
}
catch (IOException ex) 
{
    Logger.getLogger(TheDatabase.class.getName()).log(Level.SEVERE, null, ex);
}
finally 
{
    try 
    {
        db.close();
    } 
    catch (IOException ex) 
    {
        Logger.getLogger(TheDatabase.class.getName()).log(Level.SEVERE, null, ex);
    }
}

以下代码似乎可以解决问题:

Database db = DatabaseBuilder.open(new File("C:/Users/Public/mdbTest.mdb")); 
Table tbl = db.getSystemTable("MSysObjects");
Cursor crsr = tbl.getDefaultCursor();
Map<String, Object> findCriteria = new HashMap<String, Object>();
findCriteria.put("Name", "refNum");
findCriteria.put("Type", (short)1);
String status = "";
if (crsr.findFirstRow(findCriteria)) {
    tbl.deleteRow(crsr.getCurrentRow());
    status = "table dropped (row deleted from MSysObjects)";
}
else {
    status = "row not found in MSysObjects";
}
System.out.println(status);
db.close();

相关内容

  • 没有找到相关文章