2013-10-19 54 views
1

我是Jackcess的新成員。我必須在Jackcess的幫助下從數據庫中選擇一列,然後將該列的值放入數組中。如何選擇Jackcess的色譜柱

如何在Jackcess的幫助下做到這一點?

+0

我從你最近的其他問題[這裏](http://stackoverflow.com/q/19444607/2144390)和[這裏](http://stackoverflow.com/q/19450755/2144390)看到你真的只需要一些幫助入門。您是否偶然使用Eclipse作爲集成開發環境(IDE)? –

+0

不,我正在使用NetBeans作爲我的IDE,並且我正在製作程序以將來自訪問數據庫的列的值放入數組中,然後匹配它們,但jdbc不起作用。我有缺少驅動程序,我已經嘗試解決這個問題,但我還沒有找到可接受的解決方案,並且jackcess也不適合我 – Sarah

回答

2

以下代碼檢索[的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(); 
     } 
    } 
}