@Override
    public void updateMatch(Match match) {
        validate(match);
        checkDataSource();

        try (Connection conn = dataSource.getConnection();
                PreparedStatement st = conn.prepareStatement("UPDATE MATCHES SET hometeamid = ?, awayteamid = ?, date = ?, homeowngoals = ?, awayowngoals = ?"
                        + ", homeadvantagegoals = ?, awayadvantagegoals = ?, homecontumationgoals = ?, awaycontumationgoals = ?, hometechnicalgoals = ?, awaytechnicalgoals = ?, matchresult = ?"
                        + " WHERE id = ?")) {
            st.setLong(1, match.getHomeTeam().getId());
            st.setLong(2, match.getAwayTeam().getId());
            st.setDate(3, match.getDatePlayed());
            st.setInt(4, match.getOwnGoals().getHomeScore());
            st.setInt(5, match.getOwnGoals().getAwayScore());
            st.setInt(6, match.getAdvantageGoals().getHomeScore());
            st.setInt(7, match.getAdvantageGoals().getAwayScore());
            st.setInt(8, match.getContumationGoals().getHomeScore());
            st.setInt(9, match.getContumationGoals().getAwayScore());
            st.setInt(10, match.getTechnicalGoals().getHomeScore());
            st.setInt(11, match.getTechnicalGoals().getAwayScore());
            st.setString(12, match.getResult().toString());
            st.setLong(13, match.getId());

            int addedRows = st.executeUpdate();

            if (addedRows != 1) {
                throw new ServiceFailureException("Internal Error: failed when trying to update match " + match);
            }
            try (PreparedStatement st2 = conn.prepareStatement("DELETE FROM GOALS WHERE matchid = ?")) {
                st2.setLong(1, match.getId());

                st2.executeUpdate();

            } catch (SQLException ex) {
                String msg = "error when updating stage 2 match" + match;
                Logger.getLogger(TeamMngrImpl.class.getName()).log(Level.SEVERE, msg, ex);
                throw new ServiceFailureException(msg);
            }

            for (Player player : match.getGoalsScored().keySet()) {

                try (PreparedStatement st2 = conn.prepareStatement("INSERT INTO GOALS (playerid, matchid, amount) VALUES (?,?,?)")) {
                    st2.setLong(1, player.getId());
                    st2.setLong(2, match.getId());
                    st2.setInt(3, match.getGoalsScored().get(player));

                    int addedRows2 = st2.executeUpdate();

                    if (addedRows2 != 1) {
                        throw new ServiceFailureException("Internal Error: More rows inserted when trying to insert match " + match);
                    }

                } catch (SQLException ex) {
                    String msg = "error when updating stage 3 match" + match;
                    Logger.getLogger(TeamMngrImpl.class.getName()).log(Level.SEVERE, msg, ex);
                    throw new ServiceFailureException(msg);
                }
            }

        } catch (SQLException ex) {
            String msg = "error when updating stage 1 match" + match;
            Logger.getLogger(TeamMngrImpl.class.getName()).log(Level.SEVERE, msg, ex);
            throw new ServiceFailureException(msg);
        }
    }