public long fillTables() {
    Iterator it = tables.listIterator();    // list of relevant source-tables
    String srctable="";                     // holds name of current source-table
    long rowcount = 0;
		
    // add the database identifier into the SELECT statement
    queryStr = queryStr.replaceAll("databaseID", ""+databaseID);

    // iterate through all relevant source-tables
    while (it.hasNext()) {
      try {
         // extract data from source table and store it into remote temporary database
         srctable = (String)it.next();
         rowcount += sourceDB.executeUpdate("INSERT IGNORE INTO "+tmpTable+" "+queryStr.replaceAll("#srctable#",srctable));
      } catch (SQLException e) {
         // error, report to caller
         output += "Error while filling temporary database from source table "+srctable+"!";
         output += "<p>"+e.getMessage()+"<p>";        
         success = false;
	 return 0;
      }
    }

    // copy data from remote temporary table into local temporary table via mysqldump
    // (needs not be done if remote and local databases are the same)
    if (!dbIdentical) try {
        // different syntax for calling command line in windows and linux
        String os = System.getProperty("os.name").toLowerCase();
        Runtime rt=Runtime.getRuntime();
        String[] command = {"","",""};
        if (os.indexOf("windows")>-1) {
            command[0] = "cmd.exe";
            command[1] = "/c";
        } else {
            command[0] = "/bin/sh";
            command[1] = "-c";
        }
        // build mysqldump-command
        // check if port was given
        String sourceHost = "";
        String sourcePort = "";
        if (sourceInfo.getHost().indexOf(":")>-1) {
            sourceHost = sourceInfo.getHost().split(":")[0];
            sourcePort = "--port="+sourceInfo.getHost().split(":")[1];
        } else sourceHost = sourceInfo.getHost();
        String destHost = "";
        String destPort = "";
        if (destInfo.getHost().indexOf(":")>-1) {
            destHost = destInfo.getHost().split(":")[0];
            destPort = "--port="+destInfo.getHost().split(":")[1];
        } else destHost = destInfo.getHost();
        

        if (sourceInfo.isUseSSH()) {
            // Version mit SSH
            command[2] = "ssh -q "+sourceHost+" mysqldump "+sourcePort+" --user="+sourceInfo.getUser()
                +" --password="+sourceInfo.getPassword()+" -t --compact --lock-tables=FALSE "+sourceInfo.getName()
                +" "+tmpTable;
        } else {
            // Version ohne SSH
            command[2] = "mysqldump --host="+sourceHost+" "+sourcePort+" --user="+sourceInfo.getUser()
                +" --password="+sourceInfo.getPassword()+" -t --compact --compress --lock-tables=FALSE "+sourceInfo.getName()
                +" "+tmpTable;
        }
        if (destInfo.isUseSSH()) {
            // Version mit SSH
            command[2] += " | ssh -q "+destHost+" mysql "+destPort+" --user="+destInfo.getUser()
                +" --password="+destInfo.getPassword()+" -C "+destInfo.getName();
        
        } else {
            // Version ohne SSH
            command[2] += " | mysql --host="+destHost+" "+destPort+" --user="+destInfo.getUser()
                +" --password="+destInfo.getPassword()+" "+destInfo.getName();
        }
        
        
        // execute command and wait for it to finish
        Process proc=rt.exec(command);
        /*BufferedInputStream bis = new BufferedInputStream(proc.getErrorStream());
        int i=0;
        while ((i = bis.read())!=-1) { 
            output+=(char)i;
        }*/
        Thread.yield();
        proc.waitFor();
    } catch (Exception e) {
        // error, report to caller
        output += "Error while filling temporary database from source table "+srctable+" with mysqldump!";
        output += "<p>"+e.getMessage()+"<p>";        
        success = false;
	return 0;
    }
    return rowcount;
  }