简体   繁体   English

如何使用Jackcess选择列

[英]How to select a column with Jackcess

I am new to Jackcess. 我是Jackcess的新手。 I have to select a column from the database with the help of Jackcess and then put the values of that column in an array. 我必须借助Jackcess从数据库中选择一列,然后将该列的值放入数组中。

How can I do that with the help of Jackcess? 在Jackcess的帮助下,我该怎么做?

The following code retrieves the [SerialNumber] field for each row in the [Inventory] table and stores it in a String[] array: 以下代码为[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();
        }
    }
}

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM