Getting the number of rows in a Result Set

This trick should resolve your problem:

try {
    // scrollowalny ResultSet
    Statement stmt = 
        connection.createStatement(
        ResultSet.TYPE_SCROLL_INSENSITIVE,
        ResultSet.CONCUR_READ_ONLY);
    ResultSet resultSet = 
        stmt.executeQuery("SELECT * FROM t_t1");

    resultSet.last();
    int rowCount = resultSet.getRow();
    resultSet.beforeFirst();
    
    // teraz mozna dalej uzywac
    // do woli ResultSeta
    ...
} catch(SQLException e) {
    e.printStackTrace();
    // lub jakies bardziej eleganckie:
    log.error(e.getMessage());
}