Interface DatabaseConnection
-
- All Superinterfaces:
AutoCloseable
public interface DatabaseConnection extends AutoCloseable
A Database Connection. See Examples.java for examples.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
close()
void
executeQuery(String sql, Object[] parameters, ResultSetCallback callback)
Execute a query and process the result using a callback.ResultSet
executeQueryAutoClose(String sql, Object... parameters)
Execute a query and return the result set, the result set will be automatically closed if the user does not do so.int
executeUpdate(String sql, Object... parameters)
Execute an update and return the number of rows updated.boolean
getCloseOnReturn()
Will the connection be physically closed, or returned to the pool?Connection
getWrappedConnectionAutoClose()
Get the underlying connection.void
setCloseOnReturn()
Sets closeOnReturn, meaning that the connection is physically closed, rather than returned to the connection pool.
-
-
-
Method Detail
-
close
void close() throws SQLException
- Specified by:
close
in interfaceAutoCloseable
- Throws:
SQLException
-
executeQuery
void executeQuery(String sql, Object[] parameters, ResultSetCallback callback) throws SQLException
Execute a query and process the result using a callback.- Parameters:
sql
- the SQLparameters
- The parameters, may be null for no parameters, may containOutputParameter
andNull
objects, if an array is passed no element may be null.callback
- the callback to pass the ResultSet to.- Throws:
SQLException
- if an error occurs.- See Also:
for an example
-
executeQueryAutoClose
ResultSet executeQueryAutoClose(String sql, Object... parameters) throws SQLException
Execute a query and return the result set, the result set will be automatically closed if the user does not do so. You may call close() on the result early.- Parameters:
sql
- the SQLparameters
- The parameters may containOutputParameter
andNull
objects, if an array is passed no element may be null.- Returns:
- the result set.
- Throws:
SQLException
- if an error occurs.- See Also:
for an example
-
executeUpdate
int executeUpdate(String sql, Object... parameters) throws SQLException
Execute an update and return the number of rows updated.- Parameters:
sql
- the SQLparameters
- The parameters may containOutputParameter
andNull
objects, if an array is passed no element may be null.- Returns:
- the number of rows updated.
- Throws:
SQLException
- if an error occurs.- See Also:
for an example
-
getWrappedConnectionAutoClose
Connection getWrappedConnectionAutoClose() throws SQLException
Get the underlying connection. This is wrapped using dynamic proxies to ensure resources are closed correctly. This connection may be cast toUnwrap
in order to be unwrapped. Note that unwrapping a connection is done at the customer's own risk and means that no support will be provided for resource management issues.- Returns:
- the connection.
- Throws:
SQLException
- if an error occurs.- See Also:
for an example
-
getCloseOnReturn
boolean getCloseOnReturn()
Will the connection be physically closed, or returned to the pool?- Returns:
- true, when the connection is physically closed and not returned to the pool, when the connection is closed. False, when the connection is returned to the pool, when the connection is closed.
-
setCloseOnReturn
void setCloseOnReturn()
Sets closeOnReturn, meaning that the connection is physically closed, rather than returned to the connection pool.
-
-