Class Database

  • All Implemented Interfaces:
    java.lang.AutoCloseable

    public final class Database
    extends java.lang.Object
    implements java.lang.AutoCloseable
    Database object that allows communication with a SQL database.
    Since:
    1.3.0
    • Constructor Summary

      Constructors 
      Constructor Description
      Database​(DatabaseConnectionInfo info)
      Creates a database object with the specified parameters.
      Database​(java.lang.String dbFilePath, DatabaseType type)
      Creates a database object with the specified parameters.
      Database​(java.lang.String dbFilePath, java.lang.String username, java.lang.String password, DatabaseType type)
      Creates a database object with the specified parameters.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Releases this database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed, It is generally good practice to release resources as soon as you are finished with them to avoid tying up database resources.
      boolean equals​(java.lang.Object o)  
      Database.Connection getConnection()
      Allows management of the connection to the database.
      Database.Info getInfo()
      Returns info about the database.
      Database.Settings getSettings()
      Allows setting and retrieval of settings values from the database.
      Database.Tasks getTasks()
      Runs tasks against the database.
      int hashCode()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Database

        public Database​(java.lang.String dbFilePath,
                        java.lang.String username,
                        java.lang.String password,
                        DatabaseType type)
                 throws java.sql.SQLException
        Creates a database object with the specified parameters.
        Parameters:
        dbFilePath - File path to the database to connect to
        username - Username to use to connect to the database, ignored if blank
        password - Password to use to connect to the database, ignored if blank
        type - The database type
        Throws:
        java.sql.SQLException - if initial connection fails
        Since:
        1.4.0, constructor connects to database by running getConnection().connect().
      • Database

        public Database​(java.lang.String dbFilePath,
                        DatabaseType type)
                 throws java.sql.SQLException
        Creates a database object with the specified parameters.
        Parameters:
        dbFilePath - File path to the database to connect to
        type - The database type
        Throws:
        java.sql.SQLException - if initial connection fails
      • Database

        public Database​(DatabaseConnectionInfo info)
                 throws java.sql.SQLException
        Creates a database object with the specified parameters.
        Parameters:
        info - An object containing the database path, username, password and database type
        Throws:
        java.sql.SQLException - if initial connection fails
    • Method Detail

      • getConnection

        public Database.Connection getConnection()
        Allows management of the connection to the database.
        Returns:
        instance of the Connection class
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getInfo

        public Database.Info getInfo()
        Returns info about the database.
        Returns:
        instance of the Info class
      • getTasks

        public Database.Tasks getTasks()
        Runs tasks against the database.
        Returns:
        instance of the Tasks class
      • getSettings

        public Database.Settings getSettings()
        Allows setting and retrieval of settings values from the database.
        Returns:
        instance of the Settings class
      • close

        public void close()
                   throws java.sql.SQLException
        Releases this database and JDBC resources immediately instead of waiting for this to happen when it is automatically closed, It is generally good practice to release resources as soon as you are finished with them to avoid tying up database resources.
        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        java.sql.SQLException