Class DatabaseConnection

java.lang.Object
com.mirth.connect.server.userutil.DatabaseConnection

public class DatabaseConnection extends Object
Provides the ability to run SQL queries again the database connection object instantiated using DatabaseConnectionFactory.
  • Constructor Details

    • DatabaseConnection

      public DatabaseConnection(String address) throws SQLException
      Instantiates a new database connection with the given server address.
      Parameters:
      address - The server address to connect to.
      Throws:
      SQLException - If a database access error occurs.
    • DatabaseConnection

      public DatabaseConnection(String address, Properties info) throws SQLException
      Instantiates a new database connection with the given server address and connection arguments.
      Parameters:
      address - The server address to connect to.
      info - A Properties object containing all applicable connection arguments.
      Throws:
      SQLException - If a database access error occurs.
    • DatabaseConnection

      public DatabaseConnection(Driver driver, String address) throws SQLException
      Instantiates a new database connection with the given driver instance and server address.
      Parameters:
      driver - The explicit driver instance to connect with.
      address - The server address to connect to.
      Throws:
      SQLException - If a database access error occurs.
    • DatabaseConnection

      public DatabaseConnection(Driver driver, String address, Properties info) throws SQLException
      Instantiates a new database connection with the given driver instance, server address, and connection arguments.
      Parameters:
      driver - The explicit driver instance to connect with.
      address - The server address to connect to.
      info - A Properties object containing all applicable connection arguments.
      Throws:
      SQLException - If a database access error occurs.
  • Method Details

    • getAddress

      public String getAddress()
      Returns the server address.
      Returns:
      The server address.
    • executeCachedQuery

      public CachedRowSet executeCachedQuery(String expression) throws SQLException
      Executes a query on the database and returns a CachedRowSet.
      Parameters:
      expression - The query expression to be executed.
      Returns:
      The result of the query, as a CachedRowSet.
      Throws:
      SQLException - If a database access error occurs.
    • executeUpdate

      public int executeUpdate(String expression) throws SQLException
      Executes an INSERT/UPDATE on the database and returns the row count.
      Parameters:
      expression - The statement to be executed.
      Returns:
      A count of the number of updated rows.
      Throws:
      SQLException - If a database access error occurs.
    • executeUpdate

      public int executeUpdate(String expression, List<Object> parameters) throws SQLException
      Executes a prepared INSERT/UPDATE statement on the database and returns the row count.
      Parameters:
      expression - The prepared statement to be executed.
      parameters - The parameters for the prepared statement.
      Returns:
      A count of the number of updated rows.
      Throws:
      SQLException - If a database access error occurs.
    • executeCachedQuery

      public CachedRowSet executeCachedQuery(String expression, List<Object> parameters) throws SQLException
      Executes a prepared query on the database and returns a CachedRowSet.
      Parameters:
      expression - The prepared statement to be executed.
      parameters - The parameters for the prepared statement.
      Returns:
      The result of the query, as a CachedRowSet.
      Throws:
      SQLException - If a database access error occurs.
    • close

      public void close()
      Closes the database connection.
    • setAutoCommit

      public void setAutoCommit(boolean autoCommit) throws SQLException
      Sets this connection's auto-commit mode to the given state.
      Parameters:
      autoCommit - The value (true or false) to set the connection's auto-commit mode to.
      Throws:
      SQLException - If a database access error occurs.
    • rollback

      public void rollback() throws SQLException
      Undoes all changes made in the current transaction and releases any database locks currently held by this Connection object.
      Throws:
      SQLException - If a database access error occurs.
    • commit

      public void commit() throws SQLException
      Makes all changes made since the previous commit/rollback permanent and releases any database locks currently held by this DatabaseConnection object.
      Throws:
      SQLException - If a database access error occurs.
    • executeUpdateAndGetGeneratedKeys

      public CachedRowSet executeUpdateAndGetGeneratedKeys(String expression) throws SQLException
      Executes an INSERT/UPDATE statement on the database and returns a CachedRowSet containing any generated keys.
      Parameters:
      expression - The statement to be executed.
      Returns:
      A CachedRowSet containing any generated keys.
      Throws:
      SQLException - If a database access error occurs.
    • executeUpdateAndGetGeneratedKeys

      public CachedRowSet executeUpdateAndGetGeneratedKeys(String expression, List<Object> parameters) throws SQLException
      Executes a prepared INSERT/UPDATE statement on the database and returns a CachedRowSet containing any generated keys.
      Parameters:
      expression - The prepared statement to be executed.
      parameters - The parameters for the prepared statement.
      Returns:
      A CachedRowSet containing any generated keys.
      Throws:
      SQLException - If a database access error occurs.
    • getConnection

      public Connection getConnection()
      Returns the database connection (java.sql.Connection) this class is using.
      Returns:
      The underlying java.sql.Connection object.