Creating Relationships
Jackcess 2.1.5 added the ability to create Relationships (and hence Foreign Key Constraints) using RelationshipBuilder
, e.g.
// example in the JavaDoc for RelationshipBuilder:
//
Relationship rel = new RelationshipBuilder("FromTable", "ToTable")
.addColumns("ID", "FK_ID")
.setReferentialIntegrity()
.setCascadeDeletes()
.toRelationship(db);
Other Items
- Creating a table with an AutoNumber field:
As shown in the cookbook, that is done using ColumnBuilder#setAutonumber(true)
.
- Setting a default value for a field:
That can be done by creating a new Property named "DefaultValue" for the column:
Table tbl = db.getTable("Donations");
Column col = tbl.getColumn("DonationDate");
PropertyMap pm = col.getProperties();
pm.put("DefaultValue", "Date()");
pm.save();
Note, however, that while this default value will be used by ACE/Jet and UCanAccess, Jackcess itself does not currently respect the "DefaultValue" property when it adds new rows to a table.