public class DatabaseConnection
extends java.lang.Object
Constructor and Description |
---|
DatabaseConnection(java.sql.Driver driver,
java.lang.String address)
Instantiates a new database connection with the given driver instance and server address.
|
DatabaseConnection(java.sql.Driver driver,
java.lang.String address,
java.util.Properties info)
Instantiates a new database connection with the given driver instance, server address, and
connection arguments.
|
DatabaseConnection(java.lang.String address)
Instantiates a new database connection with the given server address.
|
DatabaseConnection(java.lang.String address,
java.util.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.
|
javax.sql.rowset.CachedRowSet |
executeCachedQuery(java.lang.String expression)
Executes a query on the database and returns a CachedRowSet.
|
javax.sql.rowset.CachedRowSet |
executeCachedQuery(java.lang.String expression,
java.util.List<java.lang.Object> parameters)
Executes a prepared query on the database and returns a CachedRowSet.
|
int |
executeUpdate(java.lang.String expression)
Executes an INSERT/UPDATE on the database and returns the row count.
|
int |
executeUpdate(java.lang.String expression,
java.util.List<java.lang.Object> parameters)
Executes a prepared INSERT/UPDATE statement on the database and returns the row count.
|
javax.sql.rowset.CachedRowSet |
executeUpdateAndGetGeneratedKeys(java.lang.String expression)
Executes an INSERT/UPDATE statement on the database and returns a CachedRowSet containing any
generated keys.
|
javax.sql.rowset.CachedRowSet |
executeUpdateAndGetGeneratedKeys(java.lang.String expression,
java.util.List<java.lang.Object> parameters)
Executes a prepared INSERT/UPDATE statement on the database and returns a CachedRowSet
containing any generated keys.
|
java.lang.String |
getAddress()
Returns the server address.
|
java.sql.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(java.lang.String address) throws java.sql.SQLException
address
- The server address to connect to.java.sql.SQLException
public DatabaseConnection(java.lang.String address, java.util.Properties info) throws java.sql.SQLException
address
- The server address to connect to.info
- A Properties object containing all applicable connection arguments.java.sql.SQLException
public DatabaseConnection(java.sql.Driver driver, java.lang.String address) throws java.sql.SQLException
address
- The server address to connect to.java.sql.SQLException
public DatabaseConnection(java.sql.Driver driver, java.lang.String address, java.util.Properties info) throws java.sql.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.java.sql.SQLException
public java.lang.String getAddress()
public javax.sql.rowset.CachedRowSet executeCachedQuery(java.lang.String expression) throws java.sql.SQLException
expression
- The query expression to be executed.java.sql.SQLException
public int executeUpdate(java.lang.String expression) throws java.sql.SQLException
expression
- The statement to be executed.java.sql.SQLException
public int executeUpdate(java.lang.String expression, java.util.List<java.lang.Object> parameters) throws java.sql.SQLException
expression
- The prepared statement to be executed.parameters
- The parameters for the prepared statement.java.sql.SQLException
public javax.sql.rowset.CachedRowSet executeCachedQuery(java.lang.String expression, java.util.List<java.lang.Object> parameters) throws java.sql.SQLException
expression
- The prepared statement to be executed.parameters
- The parameters for the prepared statement.java.sql.SQLException
public void close()
public void setAutoCommit(boolean autoCommit) throws java.sql.SQLException
autoCommit
- The value (true or false) to set the connection's auto-commit mode to.java.sql.SQLException
public void rollback() throws java.sql.SQLException
java.sql.SQLException
public void commit() throws java.sql.SQLException
java.sql.SQLException
public javax.sql.rowset.CachedRowSet executeUpdateAndGetGeneratedKeys(java.lang.String expression) throws java.sql.SQLException
expression
- The statement to be executed.java.sql.SQLException
public javax.sql.rowset.CachedRowSet executeUpdateAndGetGeneratedKeys(java.lang.String expression, java.util.List<java.lang.Object> parameters) throws java.sql.SQLException
expression
- The prepared statement to be executed.parameters
- The parameters for the prepared statement.java.sql.SQLException
public java.sql.Connection getConnection()