0

I'm using JackCess library (http://sourceforge.net/p/jackcess/) to iterate over rows of a Access database under Java. The rows are many and the performance is not that great, currently I iterate over all rows of the table with this code:

private static Table VatUnitsTable;

private void fun()
{
    for (Map<String, Object> EXVAtRow : VatUnitsTable)
    {
       VatUnit vatU = new VatUnit((String)EXVAtRow.get("UUID"));
       vatU.setExtID((Integer) EXVAtRow.get("ID"));
       //bla bla working with vatU object
    }
}

I wonder what method is called when iterating with for(.. : ..) and if it is possible to get an arrayList of all rows in one call without iterating over each row and calling an SQL method.

Thank you

dendini
  • 3,842
  • 9
  • 37
  • 74

1 Answers1

0

Ok find out a faster way to traverse row, this seems to be 4x faster even though we're talking of milliseconds.

Cursor cursor = Cursor.createCursor(VatUnitsTable;);
cursor.beforeFirst();
try
{
    while (cursor.moveToNextRow())
    {
       Map<String, Object> EXVAtRow = cursor.getCurrentRow();
       VatUnit vatU = new VatUnit((String)EXVAtRow.get("UUID"));
       vatU.setExtID((Integer) EXVAtRow.get("ID"));
       //bla bla working with vatU object
    }
 }
 catch (IOException ex)
{
    log.error(ex);
}
dendini
  • 3,842
  • 9
  • 37
  • 74
  • i can't imagine why this might be any faster. it's essentially the same code path (under the hood) as your originally posted code. – jtahlborn Oct 10 '13 at 19:18