簡體   English   中英

如何使用Jackcess選擇列

[英]How to select a column with Jackcess

我是Jackcess的新手。 我必須借助Jackcess從數據庫中選擇一列,然后將該列的值放入數組中。

在Jackcess的幫助下,我該怎么做?

以下代碼為[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