如何使用Jackcess删除(DROP)Access表

时间:2014-02-25 16:25:40

标签: java ms-access ms-access-2007 jackcess

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

如何使用Jackcess 删除表?

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

1 个答案:

答案 0 :(得分:1)

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

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