Package org.jdbi.v3.core.statement
Class PreparedBatch
- All Implemented Interfaces:
- Closeable,- AutoCloseable,- Configurable<PreparedBatch>,- ResultBearing
Represents a prepared batch statement.  Multiple bindings are added to the
 compiled statement and then executed in a single operation. This is, generally,
 a very efficient way to execute large numbers of the same statement where
 the statement only varies by the arguments bound to it.
 The statement starts with an empty binding.  You bind a single batch of parameters
 with the usual 
SqlStatement binding methods, and then call
 add() to add the current binding as a batch and then clear it.
 An entire batch can be bound and added in one go with add(Map)
 or add(Object...).- 
Constructor SummaryConstructorsConstructorDescriptionPreparedBatch(Handle handle, CharSequence sql) PreparedBatch(Handle handle, String sql) Backwards compatible constructor that takes an explicit string argument.
- 
Method SummaryModifier and TypeMethodDescriptionadd()Add the current binding as a saved batch and clear the binding.Bind arguments positionally, add the binding as a saved batch, and then clear the current binding.Bind arguments from a Map, add the binding as a saved batch, then clear the current binding.final PreparedBatchRegisters with the handle for cleaning when the handle is closed.voidclose()final booleanint[]execute()Execute the batch and return the number of rows affected for each batch part.<R> Rexecute(ResultProducer<R> producer) Executes the batch, returning the result obtained from the givenResultProducer.Execute the batch and return the mod counts as inexecute, but as a Jdbi result iterator instead of an array.executeAndReturnGeneratedKeys(String... columnNames) Deprecated.executePreparedBatch(String... columnNames) Execute the batch and give access to any generated keys returned by the operation.Returns the configuration registry associated with this object.final StatementContextReturns the statement context associated with this statement.final Handlefinal inthashCode()<R> RscanResultSet(ResultSetScanner<R> resultSetScanner) Invokes the mapper with a result set supplier, and returns the value returned by the mapper.intsize()Returns the number of bindings in this batch.Methods inherited from class org.jdbi.v3.core.statement.SqlStatementbind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bind, bindArray, bindArray, bindArray, bindArray, bindArray, bindArray, bindArray, bindArray, bindASCIIStream, bindASCIIStream, bindBean, bindBean, bindBeanList, bindBinaryStream, bindBinaryStream, bindBySqlType, bindBySqlType, bindByType, bindByType, bindByType, bindByType, bindByType, bindByType, bindFields, bindFields, bindList, bindList, bindList, bindList, bindList, bindList, bindList, bindMap, bindMethods, bindMethods, bindMethodsList, bindNamedArgumentFinder, bindNull, bindNull, bindNVarchar, bindNVarchar, bindPojo, bindPojo, bindPojo, bindPojo, bindPojo, bindPojo, cleanupHandleCommit, cleanupHandleRollback, defineList, defineList, defineNamedBindings, setQueryTimeout, toStringMethods inherited from interface org.jdbi.v3.core.config.ConfigurableaddCustomizer, configure, define, getConfig, registerArgument, registerArgument, registerArrayType, registerArrayType, registerArrayType, registerArrayType, registerCodecFactory, registerCollector, registerCollector, registerColumnMapper, registerColumnMapper, registerColumnMapper, registerColumnMapper, registerColumnMapper, registerColumnMapper, registerExtension, registerRowMapper, registerRowMapper, registerRowMapper, registerRowMapper, setMapKeyColumn, setMapValueColumn, setSqlArrayArgumentStrategy, setSqlLogger, setSqlParser, setTemplateEngine, setTimingCollectorMethods inherited from interface org.jdbi.v3.core.result.ResultBearingcollectInto, collectInto, collectInto, collectRows, map, map, map, mapTo, mapTo, mapTo, mapTo, mapToBean, mapToMap, mapToMap, mapToMap, reduceResultSet, reduceRows, reduceRows, reduceRows
- 
Constructor Details- 
PreparedBatch
- 
PreparedBatchBackwards compatible constructor that takes an explicit string argument.- See Also:
 
 
- 
- 
Method Details- 
scanResultSetDescription copied from interface:ResultBearingInvokes the mapper with a result set supplier, and returns the value returned by the mapper.- Specified by:
- scanResultSetin interface- ResultBearing
- Type Parameters:
- R- result type returned by the mapper.
- Parameters:
- resultSetScanner- result set scanner
- Returns:
- the value returned by the mapper.
 
- 
executepublic int[] execute()Execute the batch and return the number of rows affected for each batch part. Note that some database drivers might return special values likeStatement.SUCCESS_NO_INFOorStatement.EXECUTE_FAILED.- Returns:
- the number of rows affected per batch part
- See Also:
 
- 
executeAndGetModCountExecute the batch and return the mod counts as inexecute, but as a Jdbi result iterator instead of an array.- Returns:
- the number of rows affected per batch part
- See Also:
 
- 
executeAndReturnGeneratedKeysDeprecated.UseexecutePreparedBatch(String...)which has the same functionality but also returns the per-batch modified row counts.Execute the batch and give access to any generated keys returned by the operation.- Parameters:
- columnNames- The column names for generated keys.
- Returns:
- A ResultBearingobject that can be used to access the results of the batch.
 
- 
executePreparedBatchExecute the batch and give access to any generated keys returned by the operation.- Parameters:
- columnNames- The column names for generated keys.
- Returns:
- A BatchResultBearingobject that can be used to access the results of the batch and the per-batch modified row counts.
 
- 
executeExecutes the batch, returning the result obtained from the givenResultProducer.- Type Parameters:
- R- the type of the result
- Parameters:
- producer- the result producer.
- Returns:
- value returned by the result producer.
 
- 
addAdd the current binding as a saved batch and clear the binding.- Returns:
- this
 
- 
addBind arguments positionally, add the binding as a saved batch, and then clear the current binding.- Parameters:
- args- the positional arguments to bind
- Returns:
- this
 
- 
addBind arguments from a Map, add the binding as a saved batch, then clear the current binding.- Parameters:
- args- map to bind arguments from for named parameters on the statement
- Returns:
- this
 
- 
sizepublic int size()Returns the number of bindings in this batch.- Returns:
- the number of bindings in this batch.
 
- 
getHandle
- 
getConfigDescription copied from interface:ConfigurableReturns the configuration registry associated with this object.- Specified by:
- getConfigin interface- Configurable<This>
- Returns:
- the configuration registry associated with this object.
 
- 
getContextReturns the statement context associated with this statement.- Returns:
- the statement context associated with this statement.
 
- 
attachToHandleForCleanupRegisters with the handle for cleaning when the handle is closed.
 There are some situations where Statements need to be cleaned up to avoid resource leaks. This method registers the current Statement it with the Handle. If the statement or the context are cleaned by themselves, it will automatically unregister, so in normal operations, resources should not pool for cleanup with the Handle.- Since:
- 3.35.0
 
- 
closepublic void close()- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
 
- 
equals
- 
hashCodepublic final int hashCode()
 
- 
executePreparedBatch(String...)which has the same functionality but also returns the per-batch modified row counts.