【问题标题】:How to select a column with Jackcess如何使用 Jackcess 选择列
【发布时间】:2013-10-19 08:00:52
【问题描述】:

我是 Jackcess 的新手。我必须在 Jackcess 的帮助下从数据库中选择一列,然后将该列的值放入一个数组中。

如何在 Jackcess 的帮助下做到这一点?

【问题讨论】:

  • 我从您最近提出的其他问题herehere 中看到,您确实只需要一些帮助才能开始。您是否偶然使用 Eclipse 作为您的集成开发环境 (IDE)?
  • 不,我正在使用 NetBeans 作为我的 IDE,我正在编写程序以将 access 数据库中的列值放入一个数组中,然后匹配它们,但 jdbc 无法正常工作。我缺少驱动程序,我已尝试解决该问题,但我没有找到可接受的解决方案,并且 jackcess 也不适合我

标签: java ms-access jackcess


【解决方案1】:

以下代码检索 [Inventory] ​​表中每一行的 [SerialNumber] 字段,并将其存储在 String[] 数组中:

import java.io.File;
import java.io.IOException;
import com.healthmarketscience.jackcess.*;

public class jackcessTest {

    public static void main(String[] args) {
        try {
            Table table = DatabaseBuilder.open(new File("C:\\Users\\Public\\Database1.accdb")).getTable("Inventory");
            int numRows = table.getRowCount();
            String[] strArray = new String[numRows];
            int index = 0;
            for (Row row : table) {
                strArray[index++] = row.get("SerialNumber").toString();
            }
            System.out.println("The first item in the array is: " + strArray[0]);
            System.out.println("The last item in the array is: " + strArray[numRows - 1]);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

【讨论】:

    【解决方案2】:

    您可以使用这个库:https://github.com/amgohan/jackcess-orm 基于 JPA 的 ORM 与 jackcess 兼容。

    【讨论】:

      猜你喜欢
      • 2012-05-26
      • 2015-12-15
      • 1970-01-01
      • 2018-12-18
      • 2013-02-20
      • 2012-01-12
      • 2016-09-05
      • 1970-01-01
      • 2021-05-15
      相关资源
      最近更新 更多