Updating Java strings using Jackcess

I am trying to update rows with a specific value using Jackcess in Java. I use the code below and no changes are made to the lines.

What am I missing here? I feel lost as there is no documentation for these methods.

Database db = DatabaseBuilder.open(new File("Db.mdb"));
Table table = db.getTable("Table1");

Cursor cursor = CursorBuilder.createCursor(table);

Map<String, Object> map = new HashMap<String, Object>();

map.put("Active", true); // Value to be updated

for (Row row : cursor.newIterable().addMatchPattern("testnum", testNum)) { 
     cursor.updateCurrentRow(table.asUpdateRow(map));
}

db.flush();
db.close();
+4
source share
1 answer

The following code works for me:

String dbFile = "C:/Users/Public/test/DB.mdb";
try (Database db = DatabaseBuilder.open(new File(dbFile))) {
    Table table = db.getTable("Table1");
    Cursor cursor = CursorBuilder.createCursor(table);
    int testNum = 1;
    for (Row row : cursor.newIterable().addMatchPattern("testnum", testNum)) {
        row.put("active", true);
        table.updateRow(row);
    }
} catch (Exception e) {
    e.printStackTrace(System.out);
}

Note that column names are case sensitive when working with Jackcess. The above code updates the column with the name active, so

row.put("active", true);
table.updateRow(row);

works but

row.put("active", true);
table.updateRow(row);

will not work.

+1
source

Source: https://habr.com/ru/post/1543943/


All Articles