Skip to content

Instantly share code, notes, and snippets.

@cofearabi
Last active November 14, 2015 15:53
Show Gist options
  • Save cofearabi/640282f9d04c2bc9b8c2 to your computer and use it in GitHub Desktop.
Save cofearabi/640282f9d04c2bc9b8c2 to your computer and use it in GitHub Desktop.
java sample code : delete table with jackcess (drop table with jackcess)
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import com.healthmarketscience.jackcess.Cursor;
import com.healthmarketscience.jackcess.Database;
import com.healthmarketscience.jackcess.DatabaseBuilder;
import com.healthmarketscience.jackcess.Table;
public class DeleteTable {
public static void main(String[] args) {
String db_name = "/home/xxxx/Dropbox/doc/mdb/jack.mdb";
String table_name = "sample_table0";
File file = new File(db_name);
Database db=null;
try {
db = DatabaseBuilder.open(file);
Table tbl=db.getSystemTable("MSysObjects");
Cursor crsr = tbl.getDefaultCursor();
Map<String,Object> findCriteria = new HashMap<String,Object>();
findCriteria.put("Name",table_name);
findCriteria.put("Type",(short)1);
if(crsr.findFirstRow(findCriteria)){
tbl.deleteRow(crsr.getCurrentRow());
System.out.println("table deleted:" + table_name);
}else{
System.out.println("there is no table:" + table_name);
}
db.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}catch(Exception ee){
System.out.println(ee.getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment