- All Implemented Interfaces:
AutoCloseable,DbOperations
close() if not explicitly committed using
commit() or rolled back using rollback() before.
Start a new transaction using SimpleConnection.startTransaction().
Operations are not allowed on a closed, committed or rolled back transaction.
Closing an already closed transaction is a no-op.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Rollback transaction if not already committed or rolled back and restore original auto commit setting if necessary.voidcommit()Commit the transaction.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 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.voidrollback()Rollback the transaction.Create a batch statement builder for executing multiple statements in a batch.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
-
commit
Commit the transaction.No further operations are allowed on this transaction afterwards.
- See Also:
-
rollback
Rollback the transaction.No further operations are allowed on this transaction afterwards.
- See Also:
-
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
-
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
-
executeScript
Description copied from interface:DbOperationsExecute all commands in a SQL script, separated with;.- Specified by:
executeScriptin interfaceDbOperations- Parameters:
sqlScript- script to execute.
-
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
-
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
Rollback transaction if not already committed or rolled back and restore original auto commit setting if necessary.Explicitly run
commit()before to commit your transaction.No further operations are allowed on this transaction afterwards.
This does not close the connection, so you can continue using it.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceDbOperations
-