private static void executeSQLScript(Connection con, InputStream resource, Boolean autoreplace) throws IOException,
            SQLException
    {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(resource))) {
            boolean done = false;
            while (!done) {
                StringBuilder command = new StringBuilder();
                while (true) {
                    String line = in.readLine();
                    if (line == null) {
                        done = true;
                        break;
                    }
                    // Ignore comments and blank lines.
                    if (isSQLCommandPart(line)) {
                        command.append(' ').append(line);
                    }
                    if (line.trim().endsWith(";")) {
                        break;
                    }
                }
                // Send command to database.
                if (!done && !command.toString().isEmpty()) {
                    // Remove last semicolon when using Oracle or DB2 to prevent "invalid character error"
                    if (DbConnectionManager.getDatabaseType() == DbConnectionManager.DatabaseType.oracle ||
                            DbConnectionManager.getDatabaseType() == DbConnectionManager.DatabaseType.db2) {
                        command.deleteCharAt(command.length() - 1);
                    }
                    /*
                     * PreparedStatements are not useful at this Point, because no parameters are set. They also prevent the 
                     * creation of trigger in orcale, so use simple statements
                     * (see http://docs.oracle.com/cd/E11882_01/java.112/e16548/oraint.htm#CHDIIDBE)
                     */
                    Statement stmt = null;
                    try {
                        String cmdString = command.toString();
                        if (autoreplace)  {
                            cmdString = cmdString.replaceAll("jiveVersion", "ofVersion");
                        }
                        stmt = con.createStatement();
                        stmt.execute(cmdString);
                    }
                    catch (SQLException e) {
                        // Lets show what failed
                        Log.error("SchemaManager: Failed to execute SQL:\n"+command.toString());
                        throw e;
                    }
                    finally {
                        DbConnectionManager.closeStatement(stmt);
                    }
                }
            }
        }
    }
Executes a SQL script.

@param con database connection.
@param resource an input stream for the script to execute.
@param autoreplace automatically replace jiveVersion with ofVersion
@throws IOException if an IOException occurs.
@throws SQLException if an SQLException occurs.
xmppserver/src/main/java/org/jivesoftware/database/SchemaManager.java