public static final class ExtendedDatabaseConnection.ExtendedDatabaseConnectionPublic extends ExtendedDatabaseConnection
ExtendedDatabaseConnection
that offers
all the methods publicly.ExtendedDatabaseConnection.ExtendedDatabaseConnectionPublic
Constructor and Description |
---|
ExtendedDatabaseConnection.ExtendedDatabaseConnectionPublic(ExtendedDatabaseConnection.ExtendedDatabaseConnectionPublic sourceConnection)
Creates a new extended database connection with parameters taken from another connection.
|
ExtendedDatabaseConnection.ExtendedDatabaseConnectionPublic(ExtendedDatabaseConnection.ExtendedDatabaseConnectionPublic sourceConnection,
boolean lazyConnection)
Creates a new extended database connection with parameters taken from another connection.
|
ExtendedDatabaseConnection.ExtendedDatabaseConnectionPublic(java.lang.String dbConnUrl,
java.util.Properties dbConnInfo,
java.lang.String dbDriverClass)
Creates a new extended database connection.
|
ExtendedDatabaseConnection.ExtendedDatabaseConnectionPublic(java.lang.String dbConnUrl,
java.util.Properties dbConnInfo,
java.lang.String dbDriverClass,
boolean lazyConnection)
Creates a new extended database connection.
|
Modifier and Type | Method and Description |
---|---|
void |
closeConnection()
Closes connection to the database.
|
java.lang.Object |
executeDataManipulationSQL(java.lang.String sql,
boolean returnGeneratedKeys,
java.lang.Object... parameters)
Executes a data modification SQL command (i.e.
|
java.lang.Object |
executeSingleValueSQL(java.lang.String sql,
java.lang.Object... parameters)
Returns the first column of the first row returned by the given SQL command.
|
java.sql.PreparedStatement |
prepareAndExecuteStatement(java.sql.PreparedStatement statement,
java.lang.String sql,
boolean returnGeneratedKeys,
java.lang.Object... parameters)
Prepares and executes an SQL command using this storage's database connection.
|
createConnection, createDriver, executeDataManipulation, executeSingleValue, finalize, getConnection, prepareAndExecute, prepareAndExecute, resultSetToMap, toString
public ExtendedDatabaseConnection.ExtendedDatabaseConnectionPublic(java.lang.String dbConnUrl, java.util.Properties dbConnInfo, java.lang.String dbDriverClass, boolean lazyConnection) throws java.lang.IllegalArgumentException, java.sql.SQLException
dbConnUrl
- the database connection URL (e.g. "jdbc:mysql://localhost/somedb")dbConnInfo
- additional parameters of the connection (e.g. "user" and "password")dbDriverClass
- class of the database driver to use (can be null if the driver is already registered)lazyConnection
- flag whether to open the database connection immediately (false)
or when a first command is executed (true)java.lang.IllegalArgumentException
- if the connection url is null or the driver class cannot be registeredjava.sql.SQLException
- if there was a problem connecting to the databasepublic ExtendedDatabaseConnection.ExtendedDatabaseConnectionPublic(java.lang.String dbConnUrl, java.util.Properties dbConnInfo, java.lang.String dbDriverClass) throws java.lang.IllegalArgumentException, java.sql.SQLException
dbConnUrl
- the database connection URL (e.g. "jdbc:mysql://localhost/somedb")dbConnInfo
- additional parameters of the connection (e.g. "user" and "password")dbDriverClass
- class of the database driver to use (can be null if the driver is already registered)java.lang.IllegalArgumentException
- if the connection url is null or the driver class cannot be registeredjava.sql.SQLException
- if there was a problem connecting to the databasepublic ExtendedDatabaseConnection.ExtendedDatabaseConnectionPublic(ExtendedDatabaseConnection.ExtendedDatabaseConnectionPublic sourceConnection, boolean lazyConnection) throws java.sql.SQLException
sourceConnection
- the database connection from which to get the connection string and infolazyConnection
- flag whether to open the database connection immediately (false)
or when a first command is executed (true)java.sql.SQLException
- if there was a problem connecting to the databasepublic ExtendedDatabaseConnection.ExtendedDatabaseConnectionPublic(ExtendedDatabaseConnection.ExtendedDatabaseConnectionPublic sourceConnection) throws java.sql.SQLException
sourceConnection
- the database connection from which to get the connection string and infojava.sql.SQLException
- if there was a problem connecting to the databasepublic void closeConnection() throws java.sql.SQLException
ExtendedDatabaseConnection
closeConnection
in class ExtendedDatabaseConnection
java.sql.SQLException
- if there was an error while closing the connectionpublic java.sql.PreparedStatement prepareAndExecuteStatement(java.sql.PreparedStatement statement, java.lang.String sql, boolean returnGeneratedKeys, java.lang.Object... parameters) throws java.sql.SQLException
ResultSet
returned by the execution can be retrieved by Statement.getResultSet()
.
Note that if a SQLRecoverableException
is thrown while executing,
the current connection is closed
and the command
retried.statement
- the previous cached statement that matches the given sql
(can be null)sql
- the SQL command to prepare and executereturnGeneratedKeys
- flag whether to set the Statement.RETURN_GENERATED_KEYS
on the prepared statementparameters
- the values for the SQL parameters (denoted by "?" chars in the SQL command)java.sql.SQLException
- if there was an unrecoverable error when parsing or executing the SQL commandpublic java.lang.Object executeSingleValueSQL(java.lang.String sql, java.lang.Object... parameters) throws java.util.NoSuchElementException, java.sql.SQLException
sql
- the SQL command to executeparameters
- parameters for the "?" placeholders inside the SQL commandjava.util.NoSuchElementException
- if the SQL command does not return any rowjava.sql.SQLException
- if there was a problem parsing or executing the SQL commandpublic java.lang.Object executeDataManipulationSQL(java.lang.String sql, boolean returnGeneratedKeys, java.lang.Object... parameters) throws java.util.NoSuchElementException, java.sql.SQLException
generatedKeys
is true or the number of affected rows Statement.getUpdateCount()
if available.sql
- the SQL command to executereturnGeneratedKeys
- the flag whether to retrieve the keys generated automatically
by the database (e.g. when inserting)parameters
- the values for the parameters in the SQL statement;
there must be one value for every ? in the SQL statementjava.util.NoSuchElementException
- if the SQL command does not return any rowjava.sql.SQLException
- if there was a problem parsing or executing the SQL command