From 64f98b1d1067fbaa4d7cf2a825e682f845c600a7 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Thu, 26 Jul 2012 02:46:28 +0000 Subject: [PATCH] more cookbook work git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@639 f203690c-595d-4dc9-a70b-905162fa7fd2 --- src/site/xdoc/cookbook.xml | 64 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/src/site/xdoc/cookbook.xml b/src/site/xdoc/cookbook.xml index e40a403..6946c3b 100644 --- a/src/site/xdoc/cookbook.xml +++ b/src/site/xdoc/cookbook.xml @@ -27,7 +27,13 @@ may be used in places where the actual code is not relevant to the example.

+ + + + + +

@@ -68,17 +74,71 @@ Where's the data? While a Cursor 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 + 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 Map<String,Object> where the keys are the column names and the values are the strongly typed column values.

for(Map<String,Object> row : table) { - System.out.prinln("The row data is: " + row); + System.out.prinln("Look ma, a row: " + row); } +

+ So, what's in a row? Well, let's assume your "Test" table is + defined in the following way in Access: +

+
+ + + + + + + + + + + + + + + + +
Field NameData Type
IDAutoNumber (Long Integer)
NameText
SalaryCurrency
StartDateDate/Time
+
+

+ Then, given a row of data, we could inspect the various Columns and + their values like so: +

+ + Map<String,Object> row = ...; + for(Column column : table.getColumns()) { + String columnName = column.getName(); + Object value = row.get(columnName); + System.out.println("Column " + columnName + "(" + column.getType() + "): " + + value + " (" + value.getClass() + ")"); + } + + // Example Output: + // + // Column ID(LONG): 27 (java.lang.Integer) + // Column Name(TEXT): Bob Smith (java.lang.String) + // Column Name(MONEY): 50000.00 (java.math.BigDecimal) + // Column StartDate(SHORT_DATE_TIME): Mon Jan 05 09:00:00 EDT 2010 (java.util.Date) + +

+ As you can see in this example (and as previously mentioned), the + row values are strongly typed Java objects. In Jackcess, the + column types are represented by a Java enum named DataType. + The DataType javadoc details the Java types used to return row + 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. +

+ -- 2.39.5