Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 26
Script support
Mark Rotteveel edited this page Jul 19, 2015
·
1 revision
Q: Does Jaybird support script execution?
A: No, currently Jaybird does not support script execution. You have either to call isql from Java code through Runtime.exec(...) call or you parse the script yourself and submit each command separately. In latter case pay attention to SET ... commands, especially to SET TERM.
Simple script executor can look like this:
importjava.sql.Connection;
importjava.io.IOException;
importjava.sql.SQLException;
importjava.io.Reader;
importjava.sql.Statement;
publicclassScriptExecutor {
publicstaticfinalStringDEFAULT_SET_TERM = "SET TERM";
publicstaticfinalStringDEFAULT_TERM = ";";
privateStringsetTermCommand = DEFAULT_SET_TERM;
privateStringterm = DEFAULT_TERM;
publicScriptExecutor() {
}
publicScriptExecutor(StringdefaultTerm, StringsetTermCommand) {
this.term = defaultTerm;
this.setTermCommand = setTermCommand;
}
publicvoidexecuteScript(Connectionconnection, Readerin)
throwsSQLException, IOException {
StringBuffersb = newStringBuffer();
Statementstmt = connection.createStatement();
try {
intch = 0;
while ((ch = in.read()) != -1) {
sb.append((char)ch);
StringpossibleTerm = sb.substring(sb.length() - term.length());
if (possibleTerm.equals(term)) {
Stringcommand = sb.substring(0, sb.length() - term.length()).trim();
processCommand(stmt, command);
}
}
} finally {
stmt.close();
}
}
protectedvoidprocessCommand(Statementstmt, Stringcommand) throwsSQLException, IOException {
if (command.toUpperCase().startsWith(setTermCommand)) {
term = command.substring(setTermCommand.length()).trim();
} elsestmt.execute(command);
}
}