@Override
    public void createPlayer(Player player) {
        checkDataSource();
        validate(player);

        if (player.getId() != null) {
            throw new IllegalArgumentException("Player already exists " + player);
        }
        try (Connection conn = dataSource.getConnection();
                PreparedStatement st = conn.prepareStatement("INSERT INTO PLAYERS (name, surname, number, teamid, home, away, position) VALUES (?,?,?,?,?,?,?)", Statement.RETURN_GENERATED_KEYS)) {
            st.setString(1, player.getName());
            st.setString(2, player.getSurname());
            st.setInt(3, player.getPlayerNumber());
            st.setLong(4, player.getTeamID());
            st.setInt(5, player.isHome()?1:0);
            st.setInt(6, player.isAway()?1:0);
            st.setString(7, player.getPlayerPosition().toString());

            int addedRows = st.executeUpdate();

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

            ResultSet key = st.getGeneratedKeys();
            Long id = key.getLong(1);

            if (key.next()) {
                throw new IllegalArgumentException("Given ResultSet contains more rows");
            }
            player.setId(id);

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