public class DatabaseConnection extends Object
Constructor and Description |
---|
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.
|
DatabaseConnection(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.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the database connection.
|
void |
commit()
Makes all changes made since the previous commit/rollback permanent and releases any database
locks currently held by this DatabaseConnection object.
|
CachedRowSet |
executeCachedQuery(String expression)
Executes a query on the database and returns a CachedRowSet.
|
CachedRowSet |
executeCachedQuery(String expression,
List<Object> parameters)
Executes a prepared query on the database and returns a CachedRowSet.
|
int |
executeUpdate(String expression)
Executes an INSERT/UPDATE on the database and returns the row count.
|
int |
executeUpdate(String expression,
List<Object> parameters)
Executes a prepared INSERT/UPDATE statement on the database and returns the row count.
|
CachedRowSet |
executeUpdateAndGetGeneratedKeys(String expression)
Executes an INSERT/UPDATE statement on the database and returns a CachedRowSet containing any
generated keys.
|
CachedRowSet |
executeUpdateAndGetGeneratedKeys(String expression,
List<Object> parameters)
Executes a prepared INSERT/UPDATE statement on the database and returns a CachedRowSet
containing any generated keys.
|
String |
getAddress()
Returns the server address.
|
Connection |
getConnection()
Returns the database connection (java.sql.Connection) this class is using.
|
void |
rollback()
Undoes all changes made in the current transaction and releases any database locks currently
held by this Connection object.
|
void |
setAutoCommit(boolean autoCommit)
Sets this connection's auto-commit mode to the given state.
|
public DatabaseConnection(String address) throws SQLException
address
- The server address to connect to.SQLException
- If a database access error occurs.public DatabaseConnection(String address, Properties info) throws SQLException
address
- The server address to connect to.info
- A Properties object containing all applicable connection arguments.SQLException
- If a database access error occurs.public DatabaseConnection(Driver driver, String address) throws SQLException
driver
- The explicit driver instance to connect with.address
- The server address to connect to.SQLException
- If a database access error occurs.public DatabaseConnection(Driver driver, String address, Properties info) throws SQLException
driver
- The explicit driver instance to connect with.address
- The server address to connect to.info
- A Properties object containing all applicable connection arguments.SQLException
- If a database access error occurs.public String getAddress()
public CachedRowSet executeCachedQuery(String expression) throws SQLException
expression
- The query expression to be executed.SQLException
- If a database access error occurs.public int executeUpdate(String expression) throws SQLException
expression
- The statement to be executed.SQLException
- If a database access error occurs.public int executeUpdate(String expression, List<Object> parameters) throws SQLException
expression
- The prepared statement to be executed.parameters
- The parameters for the prepared statement.SQLException
- If a database access error occurs.public CachedRowSet executeCachedQuery(String expression, List<Object> parameters) throws SQLException
expression
- The prepared statement to be executed.parameters
- The parameters for the prepared statement.SQLException
- If a database access error occurs.public void close()
public void setAutoCommit(boolean autoCommit) throws SQLException
autoCommit
- The value (true or false) to set the connection's auto-commit mode to.SQLException
- If a database access error occurs.public void rollback() throws SQLException
SQLException
- If a database access error occurs.public void commit() throws SQLException
SQLException
- If a database access error occurs.public CachedRowSet executeUpdateAndGetGeneratedKeys(String expression) throws SQLException
expression
- The statement to be executed.SQLException
- If a database access error occurs.public CachedRowSet executeUpdateAndGetGeneratedKeys(String expression, List<Object> parameters) throws SQLException
expression
- The prepared statement to be executed.parameters
- The parameters for the prepared statement.SQLException
- If a database access error occurs.public Connection getConnection()