Package org.h2.tools

Class RunScript


  • public class RunScript
    extends Tool
    Runs a SQL script against a database.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean checkResults  
      private boolean showResults  
      • Fields inherited from class org.h2.util.Tool

        out
    • Constructor Summary

      Constructors 
      Constructor Description
      RunScript()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void execute​(java.lang.String url, java.lang.String user, java.lang.String password, java.lang.String fileName, java.nio.charset.Charset charset, boolean continueOnError)
      Executes the SQL commands in a script file against a database.
      static java.sql.ResultSet execute​(java.sql.Connection conn, java.io.Reader reader)
      Executes the SQL commands read from the reader against a database.
      static void main​(java.lang.String... args)
      Options are case sensitive.
      (package private) void process​(java.lang.String url, java.lang.String user, java.lang.String password, java.lang.String fileName, java.nio.charset.Charset charset, boolean continueOnError)
      Executes the SQL commands in a script file against a database.
      private void process​(java.sql.Connection conn, boolean continueOnError, java.lang.String path, java.io.Reader reader, java.nio.charset.Charset charset)  
      private void process​(java.sql.Connection conn, java.lang.String fileName, boolean continueOnError, java.nio.charset.Charset charset)  
      private static void processRunscript​(java.lang.String url, java.lang.String user, java.lang.String password, java.lang.String fileName, java.lang.String options)  
      void runTool​(java.lang.String... args)
      Executes the contents of a SQL script file against a database.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • showResults

        private boolean showResults
      • checkResults

        private boolean checkResults
    • Constructor Detail

      • RunScript

        public RunScript()
    • Method Detail

      • main

        public static void main​(java.lang.String... args)
                         throws java.sql.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 - the command line arguments
        Throws:
        java.sql.SQLException - on failure
      • runTool

        public void runTool​(java.lang.String... args)
                     throws java.sql.SQLException
        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 class Tool
        Parameters:
        args - the command line arguments
        Throws:
        java.sql.SQLException - on failure
      • execute

        public static java.sql.ResultSet execute​(java.sql.Connection conn,
                                                 java.io.Reader reader)
                                          throws java.sql.SQLException
        Executes the SQL commands read from the reader against a database.
        Parameters:
        conn - the connection to a database
        reader - the reader
        Returns:
        the last result set
        Throws:
        java.sql.SQLException - on failure
      • process

        private void process​(java.sql.Connection conn,
                             java.lang.String fileName,
                             boolean continueOnError,
                             java.nio.charset.Charset charset)
                      throws java.sql.SQLException,
                             java.io.IOException
        Throws:
        java.sql.SQLException
        java.io.IOException
      • process

        private void process​(java.sql.Connection conn,
                             boolean continueOnError,
                             java.lang.String path,
                             java.io.Reader reader,
                             java.nio.charset.Charset charset)
                      throws java.sql.SQLException,
                             java.io.IOException
        Throws:
        java.sql.SQLException
        java.io.IOException
      • processRunscript

        private static void processRunscript​(java.lang.String url,
                                             java.lang.String user,
                                             java.lang.String password,
                                             java.lang.String fileName,
                                             java.lang.String options)
                                      throws java.sql.SQLException
        Throws:
        java.sql.SQLException
      • execute

        public static void execute​(java.lang.String url,
                                   java.lang.String user,
                                   java.lang.String password,
                                   java.lang.String fileName,
                                   java.nio.charset.Charset charset,
                                   boolean continueOnError)
                            throws java.sql.SQLException
        Executes the SQL commands in a script file against a database.
        Parameters:
        url - the database URL
        user - the user name
        password - the password
        fileName - the script file
        charset - the character set or null for UTF-8
        continueOnError - if execution should be continued if an error occurs
        Throws:
        java.sql.SQLException - on failure
      • process

        void process​(java.lang.String url,
                     java.lang.String user,
                     java.lang.String password,
                     java.lang.String fileName,
                     java.nio.charset.Charset charset,
                     boolean continueOnError)
              throws java.sql.SQLException
        Executes the SQL commands in a script file against a database.
        Parameters:
        url - the database URL
        user - the user name
        password - the password
        fileName - the script file
        charset - the character set or null for UTF-8
        continueOnError - if execution should be continued if an error occurs
        Throws:
        java.sql.SQLException