Top Description Inners Fields Constructors Methods
org.hsqldb.cmdline

public Class SqlTool

extends Object
Class Inheritance
Imports
java.io.BufferedReader, .File, .IOException, .InputStreamReader, .PipedReader, .PipedWriter, java.net.MalformedURLException, .URL, java.sql.Connection, .SQLException, java.util.HashMap, .Map, org.hsqldb.cmdline.sqltool.Token, org.hsqldb.cmdline.libclone.FrameworkLogger, org.hsqldb.cmdline.utilclone.RCData

A command-line JDBC SQL tool supporting both interactive and non-interactive usage.

See JavaDocs for the main method for syntax of how to run from the command-line.

Programmatic users will usually want to use the objectMain(String[]) method if they want arguments and behavior exactly like command-line SqlTool. But in many cases, you will have better control and efficiency by using the SqlFile class directly. The file src/org/hsqldb/sample/SqlFileEmbedder.java in the HSQLDB distribution provides an example for this latter strategy.

Author
Blaine Simpson (blaine dot simpson at admc dot com)
Version
$Revision: 6632 $, $Date: 2022-11-20 21:35:32 +0000 (Sun, 20 Nov 2022) $
See Also
The SqlTool chapter of the HyperSQL Utilities Guide, main(String[]), objectMain(String[]), SqlFile

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
SqlTool.BadCmdline

Utility nested class for internal use.

private static class
SqlTool.PrivateException

For trapping of exceptions inside this class.

public static class

Field Summary

Modifier and TypeField and Description
private static final SqlTool.BadCmdline
bcl

Utility object for internal use.

private static final String
CMDLINE_ID

The configuration identifier to use when connection parameters are specified on the command line

public static final int
public static final String
public static final int
public static final int
public static final int
private static final FrameworkLogger
public static final String
LS

Platform-specific line separator

public static final int
private static final String
private static final String
private static final int
public static final int
public static final int
public static final int

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static void
main(final String[]
arguments
args
)

A static wrapper for objectMain, so that that method may be executed as a Java "program".

public static void
objectMain(final String[]
Run "java... org.hsqldb.cmdline.SqlTool --help" for syntax.
arg
)

Connect to a JDBC Database and execute the commands given on stdin or in SQL file(s).

private static String

Returns:

The password the user entered
promptForPassword
(final String
The user the password is for
username
)

Prompt the user for a password.

private static void
varParser(final String
The string to parse
inVarString
,
final Map<String, String>
The map to save the paired values into
varMap
,
final boolean
Set to true if the map keys should be converted to lower case
lowerCaseKeys
)

Parses a comma delimited string of name value pairs into a Map object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bclback to summary
private static final SqlTool.BadCmdline bcl

Utility object for internal use.

CMDLINE_IDback to summary
private static final String CMDLINE_ID

The configuration identifier to use when connection parameters are specified on the command line

CONNECTERR_EXITVALback to summary
public static final int CONNECTERR_EXITVAL
DEFAULT_RCFILEback to summary
public static final String DEFAULT_RCFILE
FILEERR_EXITVALback to summary
public static final int FILEERR_EXITVAL
INPUTERR_EXITVALback to summary
public static final int INPUTERR_EXITVAL
IOERR_EXITVALback to summary
public static final int IOERR_EXITVAL
loggerback to summary
private static final FrameworkLogger logger
LSback to summary
public static final String LS

Platform-specific line separator

RCERR_EXITVALback to summary
public static final int RCERR_EXITVAL
revnumback to summary
private static final String revnum
Annotations
@SuppressWarnings:ConstantConditions
revStringback to summary
private static final String revString
revStringLengthback to summary
private static final int revStringLength
SQLERR_EXITVALback to summary
public static final int SQLERR_EXITVAL
SQLTOOLERR_EXITVALback to summary
public static final int SQLTOOLERR_EXITVAL
SYNTAXERR_EXITVALback to summary
public static final int SYNTAXERR_EXITVAL

Constructor Detail

SqlToolback to summary
public SqlTool()

Method Detail

mainback to summary
public static void main(final String[] args)

A static wrapper for objectMain, so that that method may be executed as a Java "program".

Throws only RuntimeExceptions or Errors, because this method is intended to System.exit() for all but disastrous system problems, for which the inconvenience of a stack trace would be the least of your worries.

If you don't want SqlTool to System.exit(), then use the method objectMain() instead of this method.

Parameters
args:String[]

arguments

See Also
objectMain(String[])
objectMainback to summary
public static void objectMain(final String[] arg) throws SqlToolException

Connect to a JDBC Database and execute the commands given on stdin or in SQL file(s).

This method is changed for HSQLDB 1.8.0.8 and later to never System.exit(). Developers may catch Throwables to handle all fatal situations.

Parameters
arg:String[]

Run "java... org.hsqldb.cmdline.SqlTool --help" for syntax.

Exceptions
SqlToolException:
Upon any fatal error, with useful reason as the exception's message.
promptForPasswordback to summary
private static String promptForPassword(final String username) throws PrivateException

Prompt the user for a password.

Parameters
username:String

The user the password is for

Returns:String

The password the user entered

varParserback to summary
private static void varParser(final String inVarString, final Map<String, String> varMap, final boolean lowerCaseKeys) throws PrivateException

Parses a comma delimited string of name value pairs into a Map object.

Parameters
inVarString:String

The string to parse

varMap:Map<String, String>

The map to save the paired values into

lowerCaseKeys:boolean

Set to true if the map keys should be converted to lower case

org.hsqldb.cmdline back to summary

private Class SqlTool.BadCmdline

extends Exception
Class Inheritance

Utility nested class for internal use.

Field Summary

Modifier and TypeField and Description
pack-priv static final long

Constructor Summary

AccessConstructor and Description
pack-priv

Field Detail

serialVersionUIDback to summary
pack-priv static final long serialVersionUID

Hides java.lang.Exception.serialVersionUID.

Constructor Detail

BadCmdlineback to summary
pack-priv BadCmdline()
org.hsqldb.cmdline back to summary

private Class SqlTool.PrivateException

extends Exception
Class Inheritance

For trapping of exceptions inside this class. These are always handled inside this class.

Field Summary

Modifier and TypeField and Description
pack-priv static final long

Constructor Summary

AccessConstructor and Description
pack-priv

Field Detail

serialVersionUIDback to summary
pack-priv static final long serialVersionUID

Hides java.lang.Exception.serialVersionUID.

Constructor Detail

PrivateExceptionback to summary
pack-priv PrivateException(String s)
org.hsqldb.cmdline back to summary

public Class SqlTool.SqlToolException

extends Exception
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv int
pack-priv static final long

Constructor Summary

AccessConstructor and Description
pack-priv
SqlToolException(String message, int exitValue)

pack-priv
SqlToolException(int exitValue, String message)

pack-priv
SqlToolException(int exitValue)

Field Detail

exitValueback to summary
pack-priv int exitValue
serialVersionUIDback to summary
pack-priv static final long serialVersionUID

Hides java.lang.Exception.serialVersionUID.

Constructor Detail

SqlToolExceptionback to summary
pack-priv SqlToolException(String message, int exitValue)
SqlToolExceptionback to summary
pack-priv SqlToolException(int exitValue, String message)
SqlToolExceptionback to summary
pack-priv SqlToolException(int exitValue)