You need to call ResultSet#beforeFirst() to return the cursor to the first line before you return the ResultSet object. Thus, the user will be able to use next() usual way.
resultSet.last(); rows = resultSet.getRow(); resultSet.beforeFirst(); return resultSet;
However, you have more problems with the above code. This is a database resource leak, and it is also not the right OOP approach. Find the DAO pattern. Ultimately you would like to get
public List<Operations> list() throws SQLException { // Declare Connection, Statement, ResultSet, List<Operation>. try { // Use Connection, Statement, ResultSet. while (resultSet.next()) { // Add new Operation to list. } } finally { // Close ResultSet, Statement, Connection. } return list; }
Thus, the caller should simply use List#size() to find out the number of entries.
BalusC Sep 25 '11 at 13:44 2011-09-25 13:44
source share