Module org.itsallcode.jdbc
module org.itsallcode.jdbc
Simple-JDBC is a
wrapper for the JDBC API that simplifies the use of JDBC.
- Create a
SimpleConnection- ... with a connection factory using
DriverManager, seeDataSourceConnectionFactory - ... with a
DataSource, seeDataSourceConnectionFactory - ... with an existing
Connection, seeSimpleConnection.wrap(Connection, DbDialect)
- ... with a connection factory using
- Execute statements
- ... single statement:
DbOperations.executeUpdate(String) - ... with a prepared statement and generic parameters:
DbOperations.executeUpdate(String, List) - ... with a prepared statement and custom parameter setter:
DbOperations.executeUpdate(String, org.itsallcode.jdbc.PreparedStatementSetter) - ... multiple statements in a batch:
DbOperations.statementBatch() - ... semicolon separated SQL script:
DbOperations.executeScript(String)
- ... single statement:
- Execute queries
- ...with generic result types:
DbOperations.query(String) - ...with a
RowMapper, returning custom result types:DbOperations.query(String, org.itsallcode.jdbc.resultset.RowMapper) - ...with a prepared statement and generic parameters:
DbOperations.query(String, List, org.itsallcode.jdbc.resultset.RowMapper) - ...with a prepared statement and custom parameter setter:
DbOperations.query(String, org.itsallcode.jdbc.PreparedStatementSetter, org.itsallcode.jdbc.resultset.RowMapper)
- ...with generic result types:
- Use transactions:
- Start a new transaction:
SimpleConnection.startTransaction() - Use all operations from
DbOperationsin a transaction - Rollback a transaction:
Transaction.rollback() - Commit a transaction:
Transaction.commit() - Automatic rollback using try-with-resources if not committed:
Transaction.close()
- Start a new transaction:
- Batch inserts
- ... using a
StreamorIteratorof row objects:SimpleConnection.preparedStatementBatch(java.lang.Class) - ... directly setting values of a
PreparedStatement:SimpleConnection.preparedStatementBatch()
- ... using a
- Simplified Exception Handling: converts checked exception
SQLExceptionto runtime exceptionUncheckedSQLException
-
Packages