[英]Finding Row with the column of Yes/No Type in jackcess
我正在使用Jackess 2來讀取Java中的Access文件。 下面是代碼。
在我讀的表中,我只有1行。 MS-Access中有一個名為“是/否”的名為“活動”的列。
當我打印表中的所有值時,“活動”列的值顯示為“ true”。 但是,當我嘗試使用findRow()查詢該行時,沒有匹配項。
如何在表格中查詢“活動”列?
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();
}
您需要將搜索值指定為實際的布爾值,而不是字符串。 這對我有用:
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");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.