Class DatabaseConnection
java.lang.Object
com.mirth.connect.server.userutil.DatabaseConnection
Provides the ability to run SQL queries again the database connection object instantiated using
DatabaseConnectionFactory.
-
Constructor Summary
ConstructorsConstructorDescriptionDatabaseConnection(String address) Instantiates a new database connection with the given server address.DatabaseConnection(String address, Properties info) Instantiates a new database connection with the given server address and connection arguments.DatabaseConnection(Driver driver, String address) Instantiates a new database connection with the given driver instance and server address.DatabaseConnection(Driver driver, String address, Properties info) Instantiates a new database connection with the given driver instance, server address, and connection arguments. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the database connection.voidcommit()Makes all changes made since the previous commit/rollback permanent and releases any database locks currently held by this DatabaseConnection object.executeCachedQuery(String expression) Executes a query on the database and returns a CachedRowSet.executeCachedQuery(String expression, List<Object> parameters) Executes a prepared query on the database and returns a CachedRowSet.intexecuteUpdate(String expression) Executes an INSERT/UPDATE on the database and returns the row count.intexecuteUpdate(String expression, List<Object> parameters) Executes a prepared INSERT/UPDATE statement on the database and returns the row count.executeUpdateAndGetGeneratedKeys(String expression) Executes an INSERT/UPDATE statement on the database and returns a CachedRowSet containing any generated keys.executeUpdateAndGetGeneratedKeys(String expression, List<Object> parameters) Executes a prepared INSERT/UPDATE statement on the database and returns a CachedRowSet containing any generated keys.Returns the server address.Returns the database connection (java.sql.Connection) this class is using.voidrollback()Undoes all changes made in the current transaction and releases any database locks currently held by this Connection object.voidsetAutoCommit(boolean autoCommit) Sets this connection's auto-commit mode to the given state.
-
Constructor Details
-
DatabaseConnection
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
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
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
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
Returns the server address.- Returns:
- The server address.
-
executeCachedQuery
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
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
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
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
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
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
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
Returns the database connection (java.sql.Connection) this class is using.- Returns:
- The underlying java.sql.Connection object.
-