Class Shell
java.lang.Object
org.h2.util.Tool
org.h2.tools.Shell
- All Implemented Interfaces:
Runnable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final charprivate Connectionprivate PrintStreamprivate static final intprivate InputStreamprivate booleanprivate static final intprivate intprivate BufferedReaderprivate Stringprivate Statementprivate boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidconnect()private Connectionprivate voidprivate booleanstatic voidOptions are case sensitive.protected voidPrint the string without newline, and flush.private voidprivate intprintResult(ResultSet rs, boolean asList) private intprivate intprivate int[]private voidprivate StringreadLine()private Stringprivate Stringvoidrun()INTERNAL.voidRun the shell tool with the given command line settings.voidrunTool(Connection conn, String... args) Run the shell tool with the given connection and command line settings.voidsetErr(PrintStream err) Sets the standard error stream.voidsetIn(InputStream in) Redirects the standard input.voidsetInReader(BufferedReader reader) Redirects the standard input.private voidshowHelp()Methods inherited from class Tool
isOption, printNoDatabaseFilesFound, setOut, showUsage, showUsageAndThrowUnsupportedOption, throwUnsupportedOption
-
Field Details
-
MAX_ROW_BUFFER
private static final int MAX_ROW_BUFFER- See Also:
-
HISTORY_COUNT
private static final int HISTORY_COUNT- See Also:
-
BOX_VERTICAL
private static final char BOX_VERTICAL- See Also:
-
err
-
in
-
reader
-
conn
-
stat
-
listMode
private boolean listMode -
maxColumnSize
private int maxColumnSize -
history
-
stopHide
private boolean stopHide -
serverPropertiesDir
-
-
Constructor Details
-
Shell
public Shell()
-
-
Method Details
-
main
Options are case sensitive.
If special characters don't work as expected, you may need to use -Dfile.encoding=UTF-8 (Mac OS X) or CP850 (Windows).Supported options [-help] or [-?] Print the list of options [-url "<url>"] The database URL (jdbc:h2:...) [-user <user>] The user name [-password <pwd>] The password [-driver <class>] The JDBC driver class to use (not required in most cases) [-sql "<statements>"] Execute the SQL statements and exit [-properties "<dir>"] Load the server properties from this directory - Parameters:
args- the command line arguments- Throws:
SQLException- on failure
-
setErr
Sets the standard error stream.- Parameters:
err- the new standard error stream
-
setIn
Redirects the standard input. By default, System.in is used.- Parameters:
in- the input stream to use
-
setInReader
Redirects the standard input. By default, System.in is used.- Parameters:
reader- the input stream reader to use
-
runTool
Run the shell tool with the given command line settings.- Specified by:
runToolin classTool- Parameters:
args- the command line settings- Throws:
SQLException- on failure
-
runTool
Run the shell tool with the given connection and command line settings. The connection will be closed when the shell exits. This is primary used to integrate the Shell into another application.Note: using the "-url" option in
argsdoesn't make much sense since it will override theconnparameter.- Parameters:
conn- the connectionargs- the command line settings- Throws:
SQLException- on failure
-
showHelp
private void showHelp() -
promptLoop
private void promptLoop() -
connect
- Throws:
IOExceptionSQLException
-
connectH2
private Connection connectH2(String driver, String url, String user) throws IOException, SQLException - Throws:
IOExceptionSQLException
-
print
Print the string without newline, and flush.- Parameters:
s- the string to print
-
println
-
readPassword
- Throws:
IOException
-
run
-
readLine
- Throws:
IOException
-
readLine
- Throws:
IOException
-
execute
-
printResult
- Throws:
SQLException
-
printResultAsTable
- Throws:
SQLException
-
loadRow
- Throws:
SQLException
-
printRows
-
printResultAsList
- Throws:
SQLException
-