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();
}
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");
}