java.lang.Object
org.itsallcode.jdbc.SimpleConnection
- All Implemented Interfaces:
AutoCloseable,DbOperations
A simplified version of a JDBC
Connection. Create new connections
with
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the underlyingConnection.voidexecuteScript(String sqlScript) Execute all commands in a SQL script, separated with;.intexecuteUpdate(String sql) Execute a single SQL statement.intexecuteUpdate(String sql, PreparedStatementSetter preparedStatementSetter) Execute a single SQL statement as a prepared statement with placeholders.Get database metadata.Get the original wrapped connection.Create a prepared statement batch builder for inserting or updating rows by directly setting values of aPreparedStatement.preparedStatementBatch(Class<T> rowType) Execute a SQL query and return aresult setwith genericRows.<T> SimpleResultSet<T>query(String sql, PreparedStatementSetter preparedStatementSetter, RowMapper<T> rowMapper) Execute a SQL query, set parameters and return aresult setwith rows converted to a custom typeDbOperations.Start a newTransactionby disabling auto commit if necessary.Create a batch statement builder for executing multiple statements in a batch.static SimpleConnectionwrap(Connection connection, DbDialect dialect) Wrap an existingConnectionwith aSimpleConnection.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.itsallcode.jdbc.DbOperations
executeUpdate, query, query
-
Method Details
-
wrap
Wrap an existingConnectionwith aSimpleConnection.Note: Calling
close()will close the underlying connection.- Parameters:
connection- existing connectiondialect- database dialect- Returns:
- wrapped connection
-
startTransaction
Start a newTransactionby disabling auto commit if necessary.Important: The transaction must be committed or rolled back before the connection can be used again.
- Returns:
- new transaction
-
executeUpdate
Description copied from interface:DbOperationsExecute a single SQL statement.- Specified by:
executeUpdatein interfaceDbOperations- Parameters:
sql- SQL statement- Returns:
- either the row count for SQL Data Manipulation Language (DML) statements or 0 for SQL statements that return nothing
-
executeScript
Description copied from interface:DbOperationsExecute all commands in a SQL script, separated with;.- Specified by:
executeScriptin interfaceDbOperations- Parameters:
sqlScript- script to execute.
-
executeUpdate
Description copied from interface:DbOperationsExecute a single SQL statement as a prepared statement with placeholders.- Specified by:
executeUpdatein interfaceDbOperations- Parameters:
sql- SQL statementpreparedStatementSetter- prepared statement setter- Returns:
- either the row count for SQL Data Manipulation Language (DML) statements or 0 for SQL statements that return nothing
-
query
Description copied from interface:DbOperationsExecute a SQL query and return aresult setwith genericRows.- Specified by:
queryin interfaceDbOperations- Parameters:
sql- SQL query- Returns:
- result set
-
query
public <T> SimpleResultSet<T> query(String sql, PreparedStatementSetter preparedStatementSetter, RowMapper<T> rowMapper) Description copied from interface:DbOperationsExecute a SQL query, set parameters and return aresult setwith rows converted to a custom typeDbOperations.- Specified by:
queryin interfaceDbOperations- Type Parameters:
T- generic row type- Parameters:
sql- SQL querypreparedStatementSetter- the prepared statement setterrowMapper- row mapper- Returns:
- the result set
-
statementBatch
Description copied from interface:DbOperationsCreate a batch statement builder for executing multiple statements in a batch.- Specified by:
statementBatchin interfaceDbOperations- Returns:
- batch statement builder
-
preparedStatementBatch
Description copied from interface:DbOperationsCreate a prepared statement batch builder for inserting or updating rows by directly setting values of aPreparedStatement.If you want to insert rows from an
Iteratoror aStream, useDbOperations.preparedStatementBatch(Class).- Specified by:
preparedStatementBatchin interfaceDbOperations- Returns:
- batch insert builder
-
preparedStatementBatch
Description copied from interface:DbOperationsCreate a row-based prepared statement batch builder for inserting or updating rows from anIteratoror aStream.If you want to insert rows by directly setting values of a
PreparedStatement, useDbOperations.preparedStatementBatch().- Specified by:
preparedStatementBatchin interfaceDbOperations- Type Parameters:
T- row type- Parameters:
rowType- row type- Returns:
- row-based batch insert builder
-
getMetaData
Get database metadata.- Returns:
- metadata
-
getOriginalConnection
Description copied from interface:DbOperationsGet the original wrapped connection.Use this in case of missing features in
DbOperations.- Specified by:
getOriginalConnectionin interfaceDbOperations- Returns:
- original wrapped connection
-
close
Close the underlyingConnection.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceDbOperations- See Also:
-