1
votes

I am trying to retrieve data from lotus notes database view using a java program. Below is my code:

int resultsCount = view.getEntryCount();
print("Results found in view = " + resultsCount);           

Document doc = view.getFirstDocument();
if (doc != null) {
    int count = 1;  
    while (count <= resultsCount) {
        count++;
        try {
            doc = view.getNextDocument(doc);
            if (doc == null) {
                print("Record " + count + " error. Null object.");  
            } 
        } catch (NotesException e) {
                print("Record " + count + " error. Exception.");
        }
    }
}
else {
    print("Record " + count + " error. Null object.");
}

I get below results:
Results found in view = 1567
Record 866 error. Null object.

Why is there a null document found when actually 1567 records present in the db view?
How can I resume to get rest of the records, because view.getNextDocument(doc) fails with Notes Exception after this happens.

1
Are you using ODA or did you miss the recycle()umeli
@umeli I do recycle. This is fixed now after using view.getAllEntries().getCount();Leni

1 Answers

1
votes

Fixed by using

int resultsCount = view.getAllEntries().getCount();

instead of

int resultsCount = view.getEntryCount();

Using view.getAllEntries().getCount() returns the actual entry count which is 866. I am not sure what view.getEntryCount() returns. But it is definitely not the actual document count.

Edit:
As mentioned in XPages getEntryCount vs getAllEntries().getCount() view.getEntryCount() includes replications and save conflicts. Therefore to get actual record count needs to use view.getAllEntries().getCount()