Sending text to a Terminal or iTerm2 window? How can I send text to a Terminal or iTerm window?

I'm presenting a demo of some multi-user software and would like to create several windows, programatically sending (different) text to each one, something like

send to terminal window 1:  insert into foo values('hello');
send to terminal window 2:  insert into foo values('world');
etc...


I'm currently using Terminal and iTerm, but can use any other program.
You can use the Applescript keystroke command.

tell application "iTerm" to activate
delay 0.5
tell application "System Events"
    keystroke "a"
    delay 0.2
    keystroke "b"
    delay 0.2
    keystroke space
    delay 0.2    
    keystroke "c" using control down
end tell