Package org.h2.tools
Class Shell
- java.lang.Object
-
- org.h2.util.Tool
-
- org.h2.tools.Shell
-
- All Implemented Interfaces:
java.lang.Runnable
public class Shell extends Tool implements java.lang.Runnable
Interactive command line tool to access a database using JDBC.
-
-
Field Summary
Fields Modifier and Type Field Description private static charBOX_VERTICALprivate java.sql.Connectionconnprivate java.io.PrintStreamerrprivate java.util.ArrayList<java.lang.String>historyprivate static intHISTORY_COUNTprivate java.io.InputStreaminprivate booleanlistModeprivate static intMAX_ROW_BUFFERprivate intmaxColumnSizeprivate java.io.BufferedReaderreaderprivate java.lang.StringserverPropertiesDirprivate java.sql.Statementstatprivate booleanstopHide
-
Constructor Summary
Constructors Constructor Description Shell()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidconnect()private java.sql.ConnectionconnectH2(java.lang.String driver, java.lang.String url, java.lang.String user)private voidexecute(java.lang.String sql)private booleanloadRow(java.sql.ResultSet rs, int len, java.util.ArrayList<java.lang.String[]> rows)static voidmain(java.lang.String... args)Options are case sensitive.protected voidprint(java.lang.String s)Print the string without newline, and flush.private voidprintln(java.lang.String s)private intprintResult(java.sql.ResultSet rs, boolean asList)private intprintResultAsList(java.sql.ResultSet rs)private intprintResultAsTable(java.sql.ResultSet rs)private int[]printRows(java.util.ArrayList<java.lang.String[]> rows, int len)private voidpromptLoop()private java.lang.StringreadLine()private java.lang.StringreadLine(java.lang.String defaultValue)private java.lang.StringreadPassword()voidrun()INTERNAL.voidrunTool(java.lang.String... args)Run the shell tool with the given command line settings.voidrunTool(java.sql.Connection conn, java.lang.String... args)Run the shell tool with the given connection and command line settings.voidsetErr(java.io.PrintStream err)Sets the standard error stream.voidsetIn(java.io.InputStream in)Redirects the standard input.voidsetInReader(java.io.BufferedReader reader)Redirects the standard input.private voidshowHelp()-
Methods inherited from class org.h2.util.Tool
isOption, printNoDatabaseFilesFound, setOut, showUsage, showUsageAndThrowUnsupportedOption, throwUnsupportedOption
-
-
-
-
Field Detail
-
MAX_ROW_BUFFER
private static final int MAX_ROW_BUFFER
- See Also:
- Constant Field Values
-
HISTORY_COUNT
private static final int HISTORY_COUNT
- See Also:
- Constant Field Values
-
BOX_VERTICAL
private static final char BOX_VERTICAL
- See Also:
- Constant Field Values
-
err
private java.io.PrintStream err
-
in
private java.io.InputStream in
-
reader
private java.io.BufferedReader reader
-
conn
private java.sql.Connection conn
-
stat
private java.sql.Statement stat
-
listMode
private boolean listMode
-
maxColumnSize
private int maxColumnSize
-
history
private final java.util.ArrayList<java.lang.String> history
-
stopHide
private boolean stopHide
-
serverPropertiesDir
private java.lang.String serverPropertiesDir
-
-
Method Detail
-
main
public static void main(java.lang.String... args) throws java.sql.SQLExceptionOptions 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:
java.sql.SQLException- on failure
-
setErr
public void setErr(java.io.PrintStream err)
Sets the standard error stream.- Parameters:
err- the new standard error stream
-
setIn
public void setIn(java.io.InputStream in)
Redirects the standard input. By default, System.in is used.- Parameters:
in- the input stream to use
-
setInReader
public void setInReader(java.io.BufferedReader reader)
Redirects the standard input. By default, System.in is used.- Parameters:
reader- the input stream reader to use
-
runTool
public void runTool(java.lang.String... args) throws java.sql.SQLExceptionRun the shell tool with the given command line settings.
-
runTool
public void runTool(java.sql.Connection conn, java.lang.String... args) throws java.sql.SQLExceptionRun 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:
java.sql.SQLException- on failure
-
showHelp
private void showHelp()
-
promptLoop
private void promptLoop()
-
connect
private void connect() throws java.io.IOException, java.sql.SQLException- Throws:
java.io.IOExceptionjava.sql.SQLException
-
connectH2
private java.sql.Connection connectH2(java.lang.String driver, java.lang.String url, java.lang.String user) throws java.io.IOException, java.sql.SQLException- Throws:
java.io.IOExceptionjava.sql.SQLException
-
print
protected void print(java.lang.String s)
Print the string without newline, and flush.- Parameters:
s- the string to print
-
println
private void println(java.lang.String s)
-
readPassword
private java.lang.String readPassword() throws java.io.IOException- Throws:
java.io.IOException
-
run
public void run()
INTERNAL. Hides the password by repeatedly printing backspace, backspace, >, <.- Specified by:
runin interfacejava.lang.Runnable
-
readLine
private java.lang.String readLine(java.lang.String defaultValue) throws java.io.IOException- Throws:
java.io.IOException
-
readLine
private java.lang.String readLine() throws java.io.IOException- Throws:
java.io.IOException
-
execute
private void execute(java.lang.String sql)
-
printResult
private int printResult(java.sql.ResultSet rs, boolean asList) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
printResultAsTable
private int printResultAsTable(java.sql.ResultSet rs) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
loadRow
private boolean loadRow(java.sql.ResultSet rs, int len, java.util.ArrayList<java.lang.String[]> rows) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
printRows
private int[] printRows(java.util.ArrayList<java.lang.String[]> rows, int len)
-
printResultAsList
private int printResultAsList(java.sql.ResultSet rs) throws java.sql.SQLException- Throws:
java.sql.SQLException
-
-