2

I am using jackess 2 for reading a Access file in Java. Below is the code.

In the table that I read, I have only 1 row. There is a column called "Active" of type "Yes/No" in MS-Access.

When I print all values in the table, the value of Active column is shown as "true". But when I try to query the row using findRow(), there is no match.

How can I query the table for the column "Active"?

try {
    Database db = DatabaseBuilder.open(new File(strDataPath + "DB.mdb"));
    Table table = db.getTable("03_Test_Cases");

    for(Row row : table) {
        System.out.println("Column 'a' has value: " + row.get("Active"));
        // RETURNS "true"
    }

    Row row = CursorBuilder.findRow(table, Collections.singletonMap("Active", "true"));

    if(row != null) {
       System.out.println("Found row : " + row);
    } else {
       System.out.println("Could not find row"); // Always hits here only.
    }

} catch (IOException e) {
    e.printStackTrace();
}
Purus
  • 5,701
  • 9
  • 50
  • 89

1 Answers1

1

You need to specify the search value as an actual boolean value, not a string. This works for me:

Row row = CursorBuilder.findRow(table, Collections.singletonMap("Active", true));
if (row != null) {
    System.out.println("Found row : " + row);
}
else {
    System.out.println("Could not find row");
}
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
  • Great.. I was trying in as "true" before. When I change it as per your suggestion, it works. Thanks. – Purus Apr 05 '14 at 11:10