Scanning Tables and Indexes: Java