gpt4 book ai didi

java - 在 jackcess 中查找带有是/否类型列的行

转载 作者:行者123 更新时间:2023-11-30 11:20:09 25 4
gpt4 key购买 nike

我正在使用 jackess 2 读取 Java 中的 Access 文件。下面是代码。

在我阅读的表格中,我只有 1 行。在 MS-Access 中有一个名为“Activity ”的列,类型为“是/否”。

当我打印表中的所有值时,Active 列的值显示为“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();
}

最佳答案

您需要将搜索值指定为实际的 boolean 值,而不是字符串。这对我有用:

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

关于java - 在 jackcess 中查找带有是/否类型列的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22879561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com