1

I am new to 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.

How can I do that with the help of Jackcess?

Sarah
  • 370
  • 1
  • 7
  • 25
  • I see from your other recent questions [here](http://stackoverflow.com/q/19444607/2144390) and [here](http://stackoverflow.com/q/19450755/2144390) that you really just need some help getting started. Are you by chance using Eclipse as your Integrated Development Environment (IDE)? – Gord Thompson Oct 19 '13 at 09:45
  • Nope I am using NetBeans as my IDE and I am making program to put the values of column from access database in an array and then match them but jdbc is not working. I have missing drivers and I have tried solving that problem but I haven't found acceptable solution and jackcess is also not working for me – Sarah Oct 19 '13 at 10:03

2 Answers2

2

The following code retrieves the [SerialNumber] field for each row in the [Inventory] table and stores it in a String[] array:

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();
        }
    }
}
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
0

you can use this library : https://github.com/amgohan/jackcess-orm JPA based ORM compatible with jackcess.

amgohan
  • 1,358
  • 3
  • 14
  • 24