Edit: the example was bad, caused answers unrelated to the question. Given a large select query, in a simple program like:
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet srs = stmt.executeQuery(
"SELECT AGE FROM USERS");
while (srs.next()) {
ageStdDevAccumulator += Math.Pow(averageAge - srs.getInt("AGE"),2);
}
int ageStdDev= Math.Sqrt(ageStdDevAccumulator / userCount);
I understand that once the executeQuery is ran, then the entire column of user ages is sent from the database to the program. Is that right? Could this cause a memory overflow on the server if there are too many users in the database? If so it is then possible to break the select query up into smaller chunks? And if so, it is possible to let a compiler figure this out on its own?
Thanks, A database-noob programmer.