/** Execute an insert statement */
  public Integer execute(Environment env) {
    if (this.getSql() == null || this.getSql().length() == 0)
      throw new ConfigException("Property \"sqlQuery\"  not setin " + this.getClass().getName());

    if (bridgeQuerySql == null || bridgeQuerySql.length() == 0)
      throw new RequiredException("this.bridgeQuerySql");

    SQL targetSQL = null;
    SQL bridgeSQL = null;

    PreparedStatement targetPS = null;
    Statement bridgeStatement = null;
    ResultSet bridgeRS = null;
    try {
      targetSQL = this.connect();

      if (bridgeDataSource != null) {
        bridgeSQL = SQL.connect(this.bridgeDataSource.getConnection());
      } else
        bridgeSQL =
            SQL.connect(
                this.bridgeQueryJdbcDriver,
                this.bridgeQueryConnectionURL,
                this.bridgeQueryDbUserName,
                this.bridgeQueryDbPassword);

      // Create prepared SQL
      targetPS = targetSQL.prepareStatement(this.getSql());

      /// create bridge SQL statement
      bridgeStatement = bridgeSQL.createStatement();

      // select results from bridge
      Debugger.println("Executing SQL " + bridgeQuerySql);

      bridgeRS = bridgeStatement.executeQuery(this.bridgeQuerySql);

      // get number of columns

      ResultSetMetaData metaData = bridgeRS.getMetaData();
      int bridgeColumnCount = metaData.getColumnCount();

      if (bridgeColumnCount == 0) throw new SystemException("bridgeColumnCount is 0");

      // Loop thru results
      while (bridgeRS.next()) {
        // Debugger.println(this," processing records");
        // initial prepare input in row
        for (int i = 1; i <= bridgeColumnCount; i++) {
          targetPS.setObject(i, bridgeRS.getObject(i), metaData.getColumnType(i));
        }

        // execute statement
        targetPS.execute();

        // clear parameters
        targetPS.clearParameters();
      } // ----------------------------------------------

      targetSQL.commit();

      return 1;
    } catch (SQLException e) {
      targetSQL.rollback();

      throw new SystemException(e);
    } finally {

      if (targetPS != null)
        try {
          targetPS.close();
        } catch (Exception e) {
        }

      if (targetSQL != null)
        try {
          targetSQL.dispose();
        } catch (Exception e) {
        }

      if (bridgeRS != null)
        try {
          bridgeRS.close();
        } catch (Exception e) {
        }

      if (bridgeStatement != null)
        try {
          bridgeStatement.close();
        } catch (Exception e) {
        }

      if (bridgeSQL != null)
        try {
          bridgeSQL.dispose();
        } catch (Exception e) {
        }
    }
  } // ---------------------------------------------