Package org.h2.tools
Class RunScript
java.lang.Object
org.h2.util.Tool
org.h2.tools.RunScript
Runs a SQL script against a database.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
execute
(String url, String user, String password, String fileName, Charset charset, boolean continueOnError) Executes the SQL commands in a script file against a database.static ResultSet
execute
(Connection conn, Reader reader) Executes the SQL commands read from the reader against a database.static void
Options are case sensitive.(package private) void
process
(String url, String user, String password, String fileName, Charset charset, boolean continueOnError) Executes the SQL commands in a script file against a database.private void
process
(Connection conn, boolean continueOnError, String path, Reader reader, Charset charset) private void
process
(Connection conn, String fileName, boolean continueOnError, Charset charset) private static void
void
Executes the contents of a SQL script file against a database.Methods inherited from class org.h2.util.Tool
isOption, printNoDatabaseFilesFound, setOut, showUsage, showUsageAndThrowUnsupportedOption, throwUnsupportedOption
-
Field Details
-
showResults
private boolean showResults -
checkResults
private boolean checkResults
-
-
Constructor Details
-
RunScript
public RunScript()
-
-
Method Details
-
main
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
- the command line arguments- Throws:
SQLException
- on failure
-
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.- Specified by:
runTool
in classTool
- Parameters:
args
- the command line arguments- Throws:
SQLException
- on failure
-
execute
Executes the SQL commands read from the reader against a database.- Parameters:
conn
- the connection to a databasereader
- the reader- Returns:
- the last result set
- Throws:
SQLException
- on failure
-
process
private void process(Connection conn, String fileName, boolean continueOnError, Charset charset) throws SQLException, IOException - Throws:
SQLException
IOException
-
process
private void process(Connection conn, boolean continueOnError, String path, Reader reader, Charset charset) throws SQLException, IOException - Throws:
SQLException
IOException
-
processRunscript
private static void processRunscript(String url, String user, String password, String fileName, String options) throws SQLException - Throws:
SQLException
-
execute
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
- the database URLuser
- the user namepassword
- the passwordfileName
- the script filecharset
- the character set or null for UTF-8continueOnError
- if execution should be continued if an error occurs- Throws:
SQLException
- on failure
-
process
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
- the database URLuser
- the user namepassword
- the passwordfileName
- the script filecharset
- the character set or null for UTF-8continueOnError
- if execution should be continued if an error occurs- Throws:
SQLException
-