From e374ed1471a697dbc5b524686ef893f058dbef08 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Sun, 3 Feb 2013 17:58:49 +0000 Subject: [PATCH] cookbook updates git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@656 f203690c-595d-4dc9-a70b-905162fa7fd2 --- src/site/xdoc/cookbook.xml | 83 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 3 deletions(-) diff --git a/src/site/xdoc/cookbook.xml b/src/site/xdoc/cookbook.xml index 6946c3b..ec294d3 100644 --- a/src/site/xdoc/cookbook.xml +++ b/src/site/xdoc/cookbook.xml @@ -35,7 +35,7 @@
- +

So you have an Access Database and you want to do something with it. You want to use Java, and you may not even be running on Windows (or @@ -124,7 +124,7 @@ // // Column ID(LONG): 27 (java.lang.Integer) // Column Name(TEXT): Bob Smith (java.lang.String) - // Column Name(MONEY): 50000.00 (java.math.BigDecimal) + // Column Salary(MONEY): 50000.00 (java.math.BigDecimal) // Column StartDate(SHORT_DATE_TIME): Mon Jan 05 09:00:00 EDT 2010 (java.util.Date)

@@ -135,7 +135,84 @@ values as well as the value types which are acceptable inputs for new rows (more on this later). One other thing to note in this example is that the column names in the row Map are case - sensitive strings. + sensitive strings (although other parts of the API strive to + mimic Access's love of case-insensitivity). +

+
+ +

+ Awesome, so now we can read what's already there. Of course, lots + of tools can do that. Now we want to write some data. +

+

+ The main hurdle to writing data is figuring out how to get the data + in the right columns. The primary method for adding a row to a + Table is the addRow(Object...) + method. This method should be called with the appropriate, strongly + typed Java object values in the order of the Columns of the + Table. The order of the Columns on the Table instance may + not be the same as the display order of the columns in Access. + (Re-read those last two sentences again, as it will save you a lot of + grief moving forward). +

+

+ Additionally, when adding rows, we never provide a value for any + "auto" columns. You can provide a value (any value in fact), but it + will be ignored (in the example below, we use a useful constant which + makes the intent clear to any future developer). +

+

+ So, assuming that the order of the Columns on the Table instance is + "ID", "Name", "Salary", and "StartDate", this is how we would add a + row to the "Test" table: +

+ + String name = "bob"; + BigDecimal salary = new BigDecimal("1000.00"); + Date startDate = new Date(); + + table.addRow(Column.AUTO_NUMBER, name, salary, startDate); + +

+ There you have it, a new row in your Access database. +

+
+
+
+ +

+ While updating existing content is nice, and necessary, many times + we want to create an entire new Database. While Jackcess doesn't + support everything you may need when creating a new database, it + does support a wide range of functionality, and adds more all the + time. (If you started using Jackcess a while ago, you should + definitely keep tabs on the release notes, as your knowledge of what + is possible may be out of date). +

+

+ As of version 1.2.10, Jackcess supports: +

+
    +
  • Creating databases for Access all versions 2000-2010
  • +
  • Creating columns for all simple data types
  • +
  • Creating tables with single-table Indexes
  • +
+

+ Some notable gaps: +

+
    +
  • Cannot currently create (index backed) foreign-key + constraints
  • +
  • Cannot currently create "complex" columns (attachment, + multi-value, versioned memo)
  • +
+

+ As long as your needs fall into the +

+
+ +

+

-- 2.39.5