SqlTool
2
as possible (in several cases, database-specific work-arounds are used to obtain the underlying data even though the
database doesn't provide metadata according to the JDBC specs). Unlike server-side language features, the same fea-
ture set works for any database server. Database access details may be supplied on the command line, but day-to-
day users will want to centralize JDBC connection details into a single, protected RC file. You can put connection
details (username, password, URL, and other optional settings) for scores of target databases into your RC file, then
connect to any of them whenever you want by just giving SqlTool the ID ("urlid") for that database. When you Execute
SqlTool interactively, it behaves by default exactly as you would want it to. If errors occur, you are given specific error
messages and you can decide whether to roll back your session. You can easily change this behavior to auto-commit,
exit-upon-error, etc., for the current session or for all interactive invocations. You can import or export delimiter-sep-
arated-value files. If you need to run a specific statement repeatedly, perhaps changing the WHERE clause each time,
it is very simple to define a macro.
When you Execute SqlTool with a SQL script, it also behaves by default exactly as you would want it to. If any error
is encountered, the connection will be rolled back, then SqlTool will exit with an error exit value. If you wish, you
can detect and handle error (or other) conditions yourself. For scripts expected to produce errors (like many scripts
provided by database vendors), you can have SqlTool continue-upon-error. For SQL script-writers, you will have
access to portable scripting features which you've had to live without until now. You can use variables set on the
command line or in your script. You can handle specific errors based on the output of SQL commands or of your
variables. You can chain SQL scripts, invoke external programs, dump data to files, use prepared statements, Finally,
you have a procedural language with if, foreach, while, continue, and break statements.
Platforms and SqlTool versions covered
SqlTool runs on any Java 1.5 or later platform. I know that SqlTool works well with Sun and OpenJDK JVMs. I haven't
run other vendors' JVMs in years (IBM, JRockit, etc.). As my use with OpenJDK proves that I don't depend on Sun-
specific classes, I expect it to work well with other (1.5-compatible) Java implementations.
SqlTool no longer writes any files without being explicitly instructed to. Therefore, it should work fine on read-only
systems, and you'll never have orphaned temp files left around.
The command-line examples in this chapter work as given on all platforms (if you substitute in a normalized path
in place of $HSQLDB_HOME), except where noted otherwise. When doing any significant command-line work on
Windows (especially shell scripting), you're better off to completely avoid paths with spaces or funny characters. If
you can't avoid it, use double-quotes and expect problems. As with any Java program, file or directory paths on the
command line after "java" can use forward slashes instead of back slashes (this goes for System properties and the
CLASSPATH variable too). I use forward slashes because they can be used consistently, and I don't have to contort
my fingers to type them :).
If you are using SqlTool from a HyperSQL distribution of version 1.8.x or earlier, you should use the documenta-
tion with that distribution, because this manual documents many new features, several significant changes to interac-
tive-only commands, and a few changes effecting backwards-compatibility (see next section about that). This docu-
ment is now updated for the current versions of SqlTool and SqlFile at the time I am writing this (versions 3406 and
3604 correspondingly-- SqlFile is the class which actually processes the SQL content for SqlTool). Therefore, if you
are using a version of SqlTool or SqlFile that is more than a couple revisions greater, you should find a newer version
of this document. (The imprecision is due to content-independent revision increments at build time, and the likelihood
of one or two behavior-independent bug fixes after public releases). The startup banner will report both versions when
you run SqlTool interactively. (Dotted version numbers of SqlTool and SqlFile definitely indicate ancient versions).
This guide covers SqlTool as bundled with HSQLDB after 1.8.x.
1
1
To reduce the time I will need to spend maintaining this document, in this chapter I am giving the path to the sample directory as it is in
HyperSQL 2.0.x distributions, namely, HSQLDB_HOME/sample. Users of HSQLDB before 2.0.x should translate these sample directory paths
to use HSQLDB_HOME/src/org/hsqldb/sample/....