I\'m doing a query to retrieve a large amount of IDs (integers). Instead of iterating millions of times through the ResultSet and copying everything one-by-one to an ArrayLi
Put the code in a method. It's very simple to call methods...
Off the top of my head:
public static List readInts(
PreparedStatement statement
) throws SQLException {
ResultSet results = statement.executeQuery();
try {
assert results.getMetaData().getColumnCount() == 1;
List ints = new ArrayList();
while (results.next()) {
ints.add(Integer.valueOf(results.getInt(1)));
}
return ints;
} finally {
results.close();
}
}
Then just call it as:
List ids = readInts(myStatemnet);
Done.