Top Description Fields Constructors Methods
org.h2.tools

public Class RunScript

extends Tool
Class Inheritance
Imports
java.io.BufferedReader, .File, .IOException, .Reader, java.nio.charset.Charset, .StandardCharsets, java.sql.Connection, .ResultSet, .SQLException, .Statement, java.util.concurrent.TimeUnit, org.h2.message.DbException, org.h2.store.fs.FileUtils, org.h2.util.IOUtils, .JdbcUtils, .ScriptReader, .StringUtils, .Tool

Runs a SQL script against a database.

Field Summary

Modifier and TypeField and Description
private boolean
private boolean
Inherited from org.h2.util.Tool:
out

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static ResultSet

Returns:

the last result set
execute
(Connection
the connection to a database
conn
,
Reader
the reader
reader
)

Executes the SQL commands read from the reader against a database.

public static void
execute(String
the database URL
url
,
String
the user name
user
,
String
the password
password
,
String
the script file
fileName
,
Charset
the character set or null for UTF-8
charset
,
boolean
if execution should be continued if an error occurs
continueOnError
)

Executes the SQL commands in a script file against a database.

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

Options are case sensitive.

private void
process(Connection conn, String fileName, boolean continueOnError, Charset charset)

private void
process(Connection conn, boolean continueOnError, String path, Reader reader, Charset charset)

pack-priv void
process(String
the database URL
url
,
String
the user name
user
,
String
the password
password
,
String
the script file
fileName
,
Charset
the character set or null for UTF-8
charset
,
boolean
if execution should be continued if an error occurs
continueOnError
)

Executes the SQL commands in a script file against a database.

private static void
processRunscript(String url, String user, String password, String fileName, String options)

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

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

Executes the contents of a SQL script file against a database.

Inherited from org.h2.util.Tool:
getMainClassNameisOptionprintNoDatabaseFilesFoundsetOutshowUsageshowUsageAndThrowUnsupportedOptionthrowUnsupportedOption

Field Detail

checkResultsback to summary
private boolean checkResults
showResultsback to summary
private boolean showResults

Constructor Detail

RunScriptback to summary
public RunScript()

Method Detail

executeback to summary
public static ResultSet execute(Connection conn, Reader reader) throws SQLException

Executes the SQL commands read from the reader against a database.

Parameters
conn:Connection

the connection to a database

reader:Reader

the reader

Returns:ResultSet

the last result set

Exceptions
SQLException:
on failure
executeback to summary
public static void execute(String url, String user, String password, String fileName, Charset charset, boolean continueOnError) throws SQLException

Executes the SQL commands in a script file against a database.

Parameters
url:String

the database URL

user:String

the user name

password:String

the password

fileName:String

the script file

charset:Charset

the character set or null for UTF-8

continueOnError:boolean

if execution should be continued if an error occurs

Exceptions
SQLException:
on failure
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:...)
[-user <user>] The user name (default: sa)
[-password <pwd>] The password
[-script <file>] The script file to run (default: backup.sql)
[-driver <class>] The JDBC driver class to use (not required in most cases)
[-showResults] Show the statements and the results of queries
[-checkResults] Check if the query results match the expected results
[-continueOnError] Continue even if the script contains errors
[-options ...] RUNSCRIPT options (embedded H2; -*Results not supported)
Parameters
args:String[]

the command line arguments

Exceptions
SQLException:
on failure
processback to summary
private void process(Connection conn, String fileName, boolean continueOnError, Charset charset) throws SQLException, IOException
processback to summary
private void process(Connection conn, boolean continueOnError, String path, Reader reader, Charset charset) throws SQLException, IOException
processback to summary
pack-priv void process(String url, String user, String password, String fileName, Charset charset, boolean continueOnError) throws SQLException

Executes the SQL commands in a script file against a database.

Parameters
url:String

the database URL

user:String

the user name

password:String

the password

fileName:String

the script file

charset:Charset

the character set or null for UTF-8

continueOnError:boolean

if execution should be continued if an error occurs

processRunscriptback to summary
private static void processRunscript(String url, String user, String password, String fileName, String options) throws SQLException
runToolback to summary
public void runTool(String... args) throws SQLException

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

Executes the contents of a SQL script file against a database. This tool is usually used to create a database from script. It can also be used to analyze performance problems by running the tool using Java profiler settings such as:

java -Xrunhprof:cpu=samples,depth=16 ...
To include local files when using remote databases, use the special syntax:
@INCLUDE fileName
This syntax is only supported by this tool. Embedded RUNSCRIPT SQL statements will be executed by the database.
Parameters
args:String[]

the command line arguments

Annotations
@Override
Exceptions
SQLException:

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

on failure