Don't do this here, read the number of rows before using while(rs.next())