<section name="Introduction">
<p>
This cookbook will attempt to familiarize the reader with the various
- nooks and crannies of the Jackcess API. The API is large due to the
- large feature-set that an Access Database provides, so this cookbook
- will by no means be exhaustive. However, this will hopefully give the
- reader enough useful building blocks such that the rest of the API can
- be discovered and utilized as necessary.
+ nooks and crannies of the Jackcess 2.x API. The API is large due to
+ the large feature-set that an Access Database provides, so this
+ cookbook will by no means be exhaustive. However, this will hopefully
+ give the reader enough useful building blocks such that the rest of
+ the API can be discovered and utilized as necessary.
</p>
<p>
This cookbook is a cross between a tutorial and a reference, so the
<a href="apidocs/com/healthmarketscience/jackcess/Database.html">Database</a> class.
</p>
<source>
- Database db = Database.open(new File("mydb.mdb"));
+ Database db = DatabaseBuilder.open(new File("mydb.mdb"));
</source>
<p>
That's it, now you have a Database instance (maybe this isn't that
is the best way to interact with the data in a Table, for the sake
of simplicity when just getting started, we will use the simplified
iteration provided by the Table class itself. When reading row
- data, it is generally provided as a <code>Map<String,Object></code> where the keys are the column
+ data, it is generally provided as a <a
+ href="apidocs/com/healthmarketscience/jackcess/Row.html">Row</a> where the keys are the column
names and the values are the strongly typed column values.
</p>
<source>
- for(Map<String,Object> row : table) {
+ for(Row row : table) {
System.out.prinln("Look ma, a row: " + row);
}
</source>
their values like so:
</p>
<source>
- Map<String,Object> row = ...;
+ Row row = ...;
for(Column column : table.getColumns()) {
String columnName = column.getName();
Object value = row.get(columnName);
is possible may be out of date).
</p>
<p>
- As of version 1.2.10, Jackcess supports:
+ As of version 2.0.0, Jackcess supports:
</p>
<ul>
<li>Creating databases for Access all versions 2000-2010</li>
<title>Java Library for MS Access</title>
</properties>
<body>
+
<section name="Jackcess">
<p>
Jackcess is a pure Java library for reading from and writing to MS
- Access databases (currently supporting versions 2000-2007). It is part of the <a href="http://openhms.sourceforge.net/">OpenHMS</a> project from <a href="http://www.healthmarketscience.com/">Health Market Science, Inc.</a>. It is not an application. There is no GUI. It's a
+ Access databases (currently supporting versions 2000-2010). It is part of the <a href="http://openhms.sourceforge.net/">OpenHMS</a> project from <a href="http://www.healthmarketscience.com/">Health Market Science, Inc.</a>. 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
for more info.
</p>
</section>
+
<section name="Sample code">
<p>
Here are a few snippets of code to whet your appetite. For more
unit tested, you can find even more example code in the <a href="xref-test/index.html">unit tests</a>.
</p>
<ul>
- <li>Displaying the contents of a table:
- <source>System.out.println(Database.open(new File("my.mdb")).getTable("MyTable").display());
-</source>
- </li>
<li>Iterating through the rows of a table:
- <source>Table table = Database.open(new File("my.mdb")).getTable("MyTable");
-for(Map<String, Object> row : table) {
+ <source>Table table = DatabaseBuilder.open(new File("my.mdb")).getTable("MyTable");
+for(Row row : table) {
System.out.println("Column 'a' has value: " + row.get("a"));
}
</source>
</li>
<li>Searching for a row with a specific column value:
- <source>Map<String, Object> row = Cursor.findRow(table, Collections.singletonMap("a", "foo"));
+ <source>Row row = CursorBuilder.findRow(table, Collections.singletonMap("a", "foo"));
if(row != null) {
System.out.println("Found row where 'a' == 'foo': " + row);
} else {
</source>
</li>
<li>Creating a new table and writing data into it:
- <source>Database db = Database.create(new File("new.mdb"));
+ <source>Database db = DatabaseBuilder.create(Database.FileFormat.V2000, new File("new.mdb"));
Table newTable = new TableBuilder("NewTable")
.addColumn(new ColumnBuilder("a")
- .setSQLType(Types.INTEGER)
- .toColumn())
+ .setSQLType(Types.INTEGER))
.addColumn(new ColumnBuilder("b")
- .setSQLType(Types.VARCHAR)
- .toColumn())
+ .setSQLType(Types.VARCHAR))
.toTable(db);
newTable.addRow(1, "foo");
</source>
<li>Copying the contents of a JDBC ResultSet (e.g. from an
external database) into a new table:
- <source>Database.open(new File("my.mdb")).copyTable("Imported", resultSet);</source>
+ <source>Database db = DatabaseBuilder.open(new File("my.mdb"));
+new ImportUtil.Builder(db, "Imported").importResultSet(resultSet);
+db.close();</source>
</li>
<li>Copying the contents of a CSV file into a new table:
- <source>Database.open(new File("my.mdb")).importFile("Imported2", new File("my.csv"), ",");</source>
+ <source>Database db = DatabaseBuilder.open(new File("my.mdb"));
+new ImportUtil.Builder(db, "Imported2").setDelimiter(",").importFile(new File("my.csv"));
+db.close();</source>
</li>
</ul>
</section>
+
<section name="Other Resources">
Some other jackcess related projects:
<ul>