Class Database.Tasks

  • Enclosing class:
    Database

    public final class Database.Tasks
    extends java.lang.Object
    The object that stores methods to complete database tasks, use Database.getTasks() to access methods.
    • Constructor Summary

      Constructors 
      Constructor Description
      Tasks()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean createIndex​(java.lang.String indexName, java.lang.String query, boolean suppressExistsError)
      Checks to see if a table index exists and if not, creates it using the specified sql code.
      boolean createTable​(java.lang.String tableName, java.lang.String query, boolean suppressExistsError)
      Checks to see if a table exists and if not, creates it using the specified sql code.
      boolean execute​(java.lang.String sql)
      Executes the given SQL statement, which may return multiple results.
      java.sql.ResultSet executeQuery​(java.lang.String sql)
      Executes the given SQL statement, which returns a single ResultSet object, auto-closes statement object when ResultSet object is closed.
      int executeUpdate​(java.lang.String sql)
      Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.
      int getResultRows​(java.sql.ResultSet rs)
      Returns number of rows that were returned in a ResultSet object.
      • Methods inherited from class java.lang.Object

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

      • Tasks

        public Tasks()
    • Method Detail

      • executeQuery

        public java.sql.ResultSet executeQuery​(java.lang.String sql)
                                        throws java.sql.SQLException
        Executes the given SQL statement, which returns a single ResultSet object, auto-closes statement object when ResultSet object is closed.
        Parameters:
        sql - an SQL statement to be sent to the database, typically a static SQL SELECT statement
        Returns:
        a ResultSet object that contains the data produced by the given query; never null
        Throws:
        java.sql.SQLException - if a database access error occurs or the given SQL statement produces anything other than a single ResultSet object
      • executeUpdate

        public int executeUpdate​(java.lang.String sql)
                          throws java.sql.SQLException
        Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.
        Parameters:
        sql - an SQL Data Manipulation Language (DML) statement, such as INSERT, UPDATE or DELETE; or an SQL statement that returns nothing, such as a DDL statement.
        Returns:
        either (1) the row count for SQL Data Manipulation Language (DML) statements or (2) 0 for SQL statements that return nothing
        Throws:
        java.sql.SQLException - if a database access error occurs or the given SQL statement produces a ResultSet object
      • execute

        public boolean execute​(java.lang.String sql)
                        throws java.sql.SQLException
        Executes the given SQL statement, which may return multiple results. In some (uncommon) situations, a single SQL statement may return multiple result sets and/or update counts. Normally you can ignore this unless you are (1) executing a stored procedure that you know may return multiple results or (2) you are dynamically executing an unknown SQL string.

        The execute method executes an SQL statement and indicates the form of the first result. You must then use the methods getResultSet or getUpdateCount to retrieve the result, and getMoreResults to move to any subsequent result(s).

        Parameters:
        sql - any SQL statement
        Returns:
        true if the first result is a ResultSet object; false if it is an update count or there are no results
        Throws:
        java.sql.SQLException - if a database access error occurs
      • createTable

        public boolean createTable​(java.lang.String tableName,
                                   java.lang.String query,
                                   boolean suppressExistsError)
                            throws java.sql.SQLException
        Checks to see if a table exists and if not, creates it using the specified sql code.
        Parameters:
        tableName - table name to be created
        query - sql query to be used to createUser the table
        suppressExistsError - if true suppresses error if the table already exists
        Returns:
        true if created successfully
        Throws:
        java.sql.SQLException - if a database access error occurs
      • createIndex

        public boolean createIndex​(java.lang.String indexName,
                                   java.lang.String query,
                                   boolean suppressExistsError)
                            throws java.sql.SQLException
        Checks to see if a table index exists and if not, creates it using the specified sql code.
        Parameters:
        indexName - index name to be created
        query - sql query to be used to createUser the table index
        suppressExistsError - if true suppresses error if the table index already exists
        Returns:
        true if created successfully
        Throws:
        java.sql.SQLException - if a database access error occurs
      • getResultRows

        public int getResultRows​(java.sql.ResultSet rs)
        Returns number of rows that were returned in a ResultSet object.
        Parameters:
        rs - the ResultSet object to count
        Returns:
        number of rows in specified ResultSet