private void insertGroups(long rosterID, Iterator<String> iter, Connection con) throws SQLException
    {
        PreparedStatement pstmt = null;
        try {
            pstmt = con.prepareStatement(String.format(CREATE_ROSTER_ITEM_GROUPS, DbConnectionManager.getDatabaseType().escapeIdentifier("rank")));
            pstmt.setLong(1, rosterID);
            for (int i = 0; iter.hasNext(); i++) {
                pstmt.setInt(2, i);
                String groupName = iter.next();
                pstmt.setString(3, groupName);
                try {
                    pstmt.executeUpdate();
                }
                catch (SQLException e) {
                    Log.error(e.getMessage(), e);
                }
            }
        }
        finally {
            DbConnectionManager.closeStatement(pstmt);
        }
    }
Insert the groups into the given roster item.

@param rosterID the roster ID of the item the groups belong to
@param iter an iterator over the group names to insert
@param con the database connection to use for the operation.
@throws SQLException if an SQL exception occurs.
xmppserver/src/main/java/org/jivesoftware/openfire/roster/DefaultRosterItemProvider.java