public void execute()

in src/main/org/apache/tools/ant/taskdefs/SQLExec.java [615:720]


    public void execute() throws BuildException {
        List<Transaction> savedTransaction = new Vector<>(transactions);
        String savedSqlCommand = sqlCommand;

        sqlCommand = sqlCommand.trim();

        try {
            if (srcFile == null && sqlCommand.isEmpty() && resources == null) {
                if (transactions.isEmpty()) {
                    throw new BuildException(
                        "Source file or resource collection, transactions or sql statement must be set!",
                        getLocation());
                }
            }

            if (srcFile != null && !srcFile.isFile()) {
                throw new BuildException("Source file " + srcFile
                        + " is not a file!", getLocation());
            }

            if (resources != null) {
                // deal with the resources
                for (Resource r : resources) {
                    // Make a transaction for each resource
                    Transaction t = createTransaction();
                    t.setSrcResource(r);
                }
            }

            // Make a transaction group for the outer command
            Transaction t = createTransaction();
            t.setSrc(srcFile);
            t.addText(sqlCommand);

            if (getConnection() == null) {
                // not a valid rdbms
                return;
            }

            try {
                PrintStream out = KeepAliveOutputStream.wrapSystemOut();
                try {
                    if (output != null) {
                        log("Opening PrintStream to output Resource " + output, Project.MSG_VERBOSE);
                        OutputStream os = null;
                        FileProvider fp =
                            output.as(FileProvider.class);
                        if (fp != null) {
                            os = FileUtils.newOutputStream(fp.getFile().toPath(), append);
                        } else {
                            if (append) {
                                Appendable a =
                                    output.as(Appendable.class);
                                if (a != null) {
                                    os = a.getAppendOutputStream();
                                }
                            }
                            if (os == null) {
                                os = output.getOutputStream();
                                if (append) {
                                    log("Ignoring append=true for non-appendable"
                                        + " resource " + output,
                                        Project.MSG_WARN);
                                }
                            }
                        }
                        if (outputEncoding != null) {
                            out = new PrintStream(new BufferedOutputStream(os),
                                                  false, outputEncoding);
                        } else {
                            out = new PrintStream(new BufferedOutputStream(os));
                        }
                    }

                    // Process all transactions
                    for (Transaction txn : transactions) {
                        txn.runTransaction(out);
                        if (!isAutocommit()) {
                            log("Committing transaction", Project.MSG_VERBOSE);
                            getConnection().commit();
                        }
                    }
                } finally {
                    FileUtils.close(out);
                }
            } catch (IOException | SQLException e) {
                closeQuietly();
                setErrorProperty();
                if ("abort".equals(onError)) {
                    throw new BuildException(e, getLocation());
                }
            } finally {
                try {
                    FileUtils.close(getStatement());
                } catch (SQLException ex) {
                    // ignore
                }
                FileUtils.close(getConnection());
            }

            log(goodSql + " of " + totalSql + " SQL statements executed successfully");
        } finally {
            transactions = savedTransaction;
            sqlCommand = savedSqlCommand;
        }
    }