java ResultSet, using MAX sql function
database, java, jdbc, sql
Solution
if (rs2.next()) {
maxID = rs2.getInt(1);
}
Problem
Hello here is what I want, I connect to a DB and retrieve the biggest element of the UniqueId column, and assign it to an integer variable named maxID, here is my approach: ``` int maxID = 0; Statement s2 = con.createStatement(); s2.execute("SELECT MAX(UniqueId) FROM MyTable"); ResultSet rs2 = s2.getResultSet(); // while ( rs2.next() ){ maxID = rs2.getInt(0); } ``` What would be a decent way of solving this, it feels like a very crude way by using "rs2.next()" while loop. Thanks