Jackcess

Jackcess is a pure Java library for reading from and writing to MS Access databases (currently supporting versions 2000-2010). It is part of the OpenHMS project from Health Market Science, Inc.. It is not an application. There is no GUI. It's a library, intended for other developers to use to build Java applications. Jackcess is licensed under the GNU Lesser General Public License. Take a look at our Frequently Asked Questions for more info.

All New: Jackcess 2.0

New crunchy outside, same yummy filling!

The Jackcess project has gotten a facelift. A long-overdue overhaul of the public API has been completed, and the major version number of the Jackess APi has been changed to 2.0 in order to indicate the non-backwards compatible nature of the changes (although the underlying functionality remains unchanged). Read the Upgrade Guide for full details.

Sample code

Here are a few snippets of code to whet your appetite. For more extensive examples, checkout the cookbook. And, since Jackcess is heavily unit tested, you can find even more example code in the unit tests.

  • Iterating through the rows of a table:
    Table table = DatabaseBuilder.open(new File("my.mdb")).getTable("MyTable");
    for(Row row : table) {
      System.out.println("Column 'a' has value: " + row.get("a"));
    }
    
  • Searching for a row with a specific column value:
    Row row = CursorBuilder.findRow(table, Collections.singletonMap("a", "foo"));
    if(row != null) {
      System.out.println("Found row where 'a' == 'foo': " + row);
    } else {
      System.out.println("Could not find row where 'a' == 'foo'");
    }
    
  • Creating a new table and writing data into it:
    Database db = DatabaseBuilder.create(Database.FileFormat.V2000, new File("new.mdb"));
    Table newTable = new TableBuilder("NewTable")
      .addColumn(new ColumnBuilder("a")
                 .setSQLType(Types.INTEGER))
      .addColumn(new ColumnBuilder("b")
                 .setSQLType(Types.VARCHAR))
      .toTable(db);
    newTable.addRow(1, "foo");
    
  • Copying the contents of a JDBC ResultSet (e.g. from an external database) into a new table:
    Database db = DatabaseBuilder.open(new File("my.mdb"));
    new ImportUtil.Builder(db, "Imported").importResultSet(resultSet);
    db.close();
  • Copying the contents of a CSV file into a new table:
    Database db = DatabaseBuilder.open(new File("my.mdb"));
    new ImportUtil.Builder(db, "Imported2").setDelimiter(",").importFile(new File("my.csv"));
    db.close();

Other Resources

Some other jackcess related projects:

  • mdbtools - Open Source project for reading Access files, written in C.
  • Jackcess Encrypt - Extension library for Jackcess which implements support for some forms of Microsoft Access and Microsoft Money encryption.