java.lang.Object
org.itsallcode.jdbc.SimpleConnection
- All Implemented Interfaces:
- AutoCloseable,- DbOperations
A simplified version of a JDBC 
Connection. Create new connections
 with
 - 
Method SummaryModifier 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.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.itsallcode.jdbc.DbOperationsexecuteUpdate, query, query
- 
Method Details- 
wrapWrap an existingConnectionwith aSimpleConnection.Note: Calling close()will close the underlying connection.- Parameters:
- connection- existing connection
- dialect- database dialect
- Returns:
- wrapped connection
 
- 
startTransactionStart 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
 
- 
executeUpdateDescription copied from interface:DbOperationsExecute a single SQL statement.- Specified by:
- executeUpdatein interface- DbOperations
- Parameters:
- sql- SQL statement
- Returns:
- either the row count for SQL Data Manipulation Language (DML) statements or 0 for SQL statements that return nothing
 
- 
executeScriptDescription copied from interface:DbOperationsExecute all commands in a SQL script, separated with;.- Specified by:
- executeScriptin interface- DbOperations
- Parameters:
- sqlScript- script to execute.
 
- 
executeUpdateDescription copied from interface:DbOperationsExecute a single SQL statement as a prepared statement with placeholders.- Specified by:
- executeUpdatein interface- DbOperations
- Parameters:
- sql- SQL statement
- preparedStatementSetter- prepared statement setter
- Returns:
- either the row count for SQL Data Manipulation Language (DML) statements or 0 for SQL statements that return nothing
 
- 
queryDescription copied from interface:DbOperationsExecute a SQL query and return aresult setwith genericRows.- Specified by:
- queryin interface- DbOperations
- Parameters:
- sql- SQL query
- Returns:
- result set
 
- 
querypublic <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 interface- DbOperations
- Type Parameters:
- T- generic row type
- Parameters:
- sql- SQL query
- preparedStatementSetter- the prepared statement setter
- rowMapper- row mapper
- Returns:
- the result set
 
- 
statementBatchDescription copied from interface:DbOperationsCreate a batch statement builder for executing multiple statements in a batch.- Specified by:
- statementBatchin interface- DbOperations
- Returns:
- batch statement builder
 
- 
preparedStatementBatchDescription 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 interface- DbOperations
- Returns:
- batch insert builder
 
- 
preparedStatementBatchDescription 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 interface- DbOperations
- Type Parameters:
- T- row type
- Parameters:
- rowType- row type
- Returns:
- row-based batch insert builder
 
- 
getMetaDataGet database metadata.- Returns:
- metadata
 
- 
getOriginalConnectionDescription copied from interface:DbOperationsGet the original wrapped connection.Use this in case of missing features in DbOperations.- Specified by:
- getOriginalConnectionin interface- DbOperations
- Returns:
- original wrapped connection
 
- 
closeClose the underlyingConnection.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- DbOperations
- See Also:
 
 
-