Object value = lastInsertedIds.getObject(autoIncrColumns[idx].getName());
Object value = lastInsertedIds.getObject(idx + 1);
    public void insert(Connection connection, Database model, DynaBean dynaBean) throws DynaSqlException    {        SqlDynaClass      dynaClass       = model.getDynaClassFor(dynaBean);        SqlDynaProperty[] properties      = getPropertiesForInsertion(model, dynaClass, dynaBean);        Column[]          autoIncrColumns = model.findTable(dynaClass.getTableName()).getAutoIncrementColumns();        if ((properties.length == 0) && (autoIncrColumns.length == 0))        {            _log.warn("Cannot insert instances of type " + dynaClass + " because it has no usable properties");            return;        }        String            insertSql  = createInsertSql(model, dynaClass, properties, null);        String            queryIdSql = autoIncrColumns.length > 0 ? createSelectLastInsertIdSql(model, dynaClass) : null;        PreparedStatement statement  = null;        if (_log.isDebugEnabled())        {            _log.debug("About to execute SQL: " + insertSql);        }        if ((autoIncrColumns.length > 0) && (queryIdSql == null))        {            _log.warn("The database does not support querying for auto-generated pk values");        }        try        {            statement = connection.prepareStatement(insertSql);            for (int idx = 0; idx < properties.length; idx++ )            {                setObject(statement, idx + 1, dynaBean, properties[idx]);            }            int count = statement.executeUpdate();            if (count != 1)            {                _log.warn("Attempted to insert a single row " + dynaBean +                         " in table " + dynaClass.getTableName() +                         " but changed " + count + " row(s)");            }        }        catch (SQLException ex)        {            throw new DynaSqlException("Error while inserting into the database", ex);        }        finally        {            closeStatement(statement);        }        if (queryIdSql != null)        {            Statement queryStmt       = null;            ResultSet lastInsertedIds = null;            try            {                // we'll have to commit the statement(s) because otherwise most likely                // the auto increment hasn't happened yet (the db didn't actually                // perform the insert yet so no triggering of sequences did occur)                if (!connection.getAutoCommit())                {                    connection.commit();                }                queryStmt       = connection.createStatement();                lastInsertedIds = queryStmt.executeQuery(queryIdSql);                lastInsertedIds.next();                for (int idx = 0; idx < autoIncrColumns.length; idx++)                {                    Object value = lastInsertedIds.getObject(autoIncrColumns[idx].getName());                        PropertyUtils.setProperty(dynaBean, autoIncrColumns[idx].getName(), value);                }            }            catch (NoSuchMethodException ex)            {                // Can't happen because we're using dyna beans            }            catch (IllegalAccessException ex)            {                // Can't happen because we're using dyna beans            }            catch (InvocationTargetException ex)            {                // Can't happen because we're using dyna beans            }            catch (SQLException ex)            {                throw new DynaSqlException("Error while retrieving the auto-generated primary key from the database", ex);            }            finally            {                if (lastInsertedIds != null)                {                    try                    {                        lastInsertedIds.close();                    }                    catch (SQLException ex)                    {                        // we ignore this one                    }                }                closeStatement(statement);            }        }    }