问题
I work with an MS-Access table in Java using Jackcess:
Database mdb = Database.open(new File(myPath));
Table myTable = mdb.getTable("TableName");
Is there a way to get the table sorted/ordered by one or more column(s)? Couldn't find anything in the docs.
Thanks for any hint.
回答1:
If you iterate through the Table rows using a Cursor which is backed by an Index, you will get the rows ordered by the relevant Index.
This is an example (using the 1.x API) which iterates the table based on the order of the primary key:
for(Map<String,Object> row : Cursor.createIndexCursor(table, table.getPrimaryKeyIndex())) {
// do something with row here...
}
回答2:
I was having this same issue here, but it helped.
For the folks that are using the new version of Jackcess (v: 2.1.2) here is the answer:
for (Row row : CursorBuilder.createCursor(table.getIndex("IndexToBeSorted"))){
//Your awesome code with the row here
}
Thanks!
来源:https://stackoverflow.com/questions/18787142/sort-a-table-in-jackcess