Top Description Fields Constructors Methods
org.h2.tools

public Class Shell

extends Tool
implements Runnable
Class Inheritance
All Implemented Interfaces
java.lang.Runnable
Imports
java.io.BufferedReader, .IOException, .InputStream, .InputStreamReader, .PrintStream, .StringReader, java.sql.Connection, .ResultSet, .ResultSetMetaData, .SQLException, .Statement, java.util.ArrayList, .Properties, java.util.concurrent.TimeUnit, org.h2.api.ErrorCode, org.h2.engine.Constants, org.h2.server.web.ConnectionInfo, org.h2.util.JdbcUtils, .ScriptReader, .SortedProperties, .StringUtils, .Tool, .Utils

Interactive command line tool to access a database using JDBC.

Field Summary

Modifier and TypeField and Description
private static final char
private Connection
private PrintStream
private final ArrayList<String>
private static final int
private InputStream
private boolean
private static final int
private int
private BufferedReader
private String
private Statement
private boolean
Inherited from org.h2.util.Tool:
out

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
private Connection
connectH2(String driver, String url, String user)

private void
private boolean
loadRow(ResultSet rs, int len, ArrayList<String[]> rows)

public static void
main(String...
the command line arguments
args
)

Options are case sensitive.

private void
private int
printResult(ResultSet rs, boolean asList)

private int
private int
private int[]
printRows(ArrayList<String[]> rows, int len)

private void
private String
readLine(String defaultValue)

private String
private String
public void
run()

Implements java.lang.Runnable.run.

INTERNAL.

public void
runTool(String...
the command line settings
args
)

Implements abstract org.h2.util.Tool.runTool.

Run the shell tool with the given command line settings.

public void
runTool(Connection
the connection
conn
,
String...
the command line settings
args
)

Run the shell tool with the given connection and command line settings.

public void
setErr(PrintStream
the new standard error stream
err
)

Sets the standard error stream.

public void
setIn(InputStream
the input stream to use
in
)

Redirects the standard input.

public void
setInReader(BufferedReader
the input stream reader to use
reader
)

Redirects the standard input.

private void
Inherited from org.h2.util.Tool:
getMainClassNameisOptionprintNoDatabaseFilesFoundsetOutshowUsageshowUsageAndThrowUnsupportedOptionthrowUnsupportedOption

Field Detail

BOX_VERTICALback to summary
private static final char BOX_VERTICAL
connback to summary
private Connection conn
errback to summary
private PrintStream err
historyback to summary
private final ArrayList<String> history
HISTORY_COUNTback to summary
private static final int HISTORY_COUNT
inback to summary
private InputStream in
listModeback to summary
private boolean listMode
MAX_ROW_BUFFERback to summary
private static final int MAX_ROW_BUFFER
maxColumnSizeback to summary
private int maxColumnSize
readerback to summary
private BufferedReader reader
serverPropertiesDirback to summary
private String serverPropertiesDir
statback to summary
private Statement stat
stopHideback to summary
private boolean stopHide

Constructor Detail

Shellback to summary
public Shell()

Method Detail

connectback to summary
private void connect() throws IOException, SQLException
connectH2back to summary
private Connection connectH2(String driver, String url, String user) throws IOException, SQLException
executeback to summary
private void execute(String sql)
loadRowback to summary
private boolean loadRow(ResultSet rs, int len, ArrayList<String[]> rows) throws SQLException
mainback to summary
public static void main(String... args) throws SQLException

Options are case sensitive.

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
If special characters don't work as expected, you may need to use -Dfile.encoding=UTF-8 (Mac OS X) or CP850 (Windows).
Parameters
args:String[]

the command line arguments

Exceptions
SQLException:
on failure
printlnback to summary
private void println(String s)
printResultback to summary
private int printResult(ResultSet rs, boolean asList) throws SQLException
printResultAsListback to summary
private int printResultAsList(ResultSet rs) throws SQLException
printResultAsTableback to summary
private int printResultAsTable(ResultSet rs) throws SQLException
printRowsback to summary
private int[] printRows(ArrayList<String[]> rows, int len)
promptLoopback to summary
private void promptLoop()
readLineback to summary
private String readLine(String defaultValue) throws IOException
readLineback to summary
private String readLine() throws IOException
readPasswordback to summary
private String readPassword() throws IOException
runback to summary
public void run()

Implements java.lang.Runnable.run.

INTERNAL. Hides the password by repeatedly printing backspace, backspace, >, <.

Annotations
@Override
runToolback to summary
public void runTool(String... args) throws SQLException

Implements abstract org.h2.util.Tool.runTool.

Run the shell tool with the given command line settings.

Parameters
args:String[]

the command line settings

Annotations
@Override
Exceptions
SQLException:

Doc from org.h2.util.Tool.runTool.

on failure

runToolback to summary
public void runTool(Connection conn, String... args) throws SQLException

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 args doesn't make much sense since it will override the conn parameter.

Parameters
conn:Connection

the connection

args:String[]

the command line settings

Exceptions
SQLException:
on failure
setErrback to summary
public void setErr(PrintStream err)

Sets the standard error stream.

Parameters
err:PrintStream

the new standard error stream

setInback to summary
public void setIn(InputStream in)

Redirects the standard input. By default, System.in is used.

Parameters
in:InputStream

the input stream to use

setInReaderback to summary
public void setInReader(BufferedReader reader)

Redirects the standard input. By default, System.in is used.

Parameters
reader:BufferedReader

the input stream reader to use

showHelpback to summary
private void showHelp()