In my code I use a while loop and next method on my result set. However, in this case it is taking upwards of 2 seconds to execute the next statement. Any ideas? The result set is only 4 rows. Am I not understanding exactly what the next method on the resultSet object is doing. It seems as if from the performance this is actually where the databse is getting queried.
Depending on your driver and database and any use of Statement.setFetchSize(), your driver may or may not be going across the network to the database to retrieve additional rows. Again, depending on your driver and database, this might require re-execution of the query. However, on most modern databases with adequate hardware, even with a big fetch size, the worst-case time for an execution of next() ought to be well under a 10th of a second (and with a large fetch size, most execution of next() should be under 1 millesecond).