Package org.jdbi.v3.core.statement
Class SqlStatement<This extends SqlStatement<This>>
java.lang.Object
org.jdbi.v3.core.statement.SqlStatement<This>
- All Implemented Interfaces:
Closeable,AutoCloseable,Configurable<This>
- Direct Known Subclasses:
Call,PreparedBatch,Query,Script,Update
This class provides the common functions between
Query and
Update. It defines most of the argument binding functions
used by its subclasses.-
Method Summary
Modifier and TypeMethodDescriptionfinal ThisRegisters with the handle for cleaning when the handle is closed.final Thisbind(int position, boolean value) Bind an argument positionallyfinal Thisbind(int position, byte value) Bind an argument positionallyfinal Thisbind(int position, byte[] value) Bind an argument positionallyfinal Thisbind(int position, char value) Bind an argument positionallyfinal Thisbind(int position, double value) Bind an argument positionallyfinal Thisbind(int position, float value) Bind an argument positionallyfinal Thisbind(int position, int value) Bind an argument positionallyfinal Thisbind(int position, long value) Bind an argument positionallyfinal Thisbind(int position, short value) Bind an argument positionallyfinal ThisBind an argument positionallyfinal ThisBind an argument positionallyfinal ThisBind an argument positionallyfinal ThisBind an argument positionallyfinal ThisBind an argument positionallyfinal ThisBind an argument positionallyfinal ThisBind an argument positionallyfinal ThisBind an argument positionallyfinal ThisBind an argument positionallyfinal ThisBind an argument positionallyfinal ThisBind an argument positionallyfinal Thisbind(int position, BigDecimal value) Bind an argument positionallyfinal ThisBind an argument positionallyfinal ThisBind an argument positionallyfinal ThisBind an argument positionallyfinal ThisBind an argument positionallyfinal ThisBind an argument positionallyfinal ThisBind an argument positionallyfinal ThisBind an argument positionallyfinal ThisBind an argument positionallyfinal ThisBind an argument positionallyUsed if you need to have some exotic parameter bound.final ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal Thisbind(String name, BigDecimal value) Bind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by namefinal ThisBind an argument by nameUsed if you need to have some exotic parameter bound.final ThisBind an Iterable as a SQL array.final ThisBind a Java array as a SQL array, casting each element to a new type.final ThisBind an Iterator as a SQL array.final <T> ThisbindArray(int pos, T... array) Bind a Java array as a SQL array.final ThisBind an Iterable as a SQL array.final ThisBind a Java array as a SQL array, casting each element to a new type.final ThisBind an Iterator as a SQL array.final <T> ThisBind a Java array as a SQL array.final ThisbindASCIIStream(int position, InputStream value, int length) Bind an argument positionallyfinal ThisbindASCIIStream(String name, InputStream value, int length) Bind an argument by nameBinds named parameters from JavaBean properties on the argument.Binds named parameters from JavaBean properties on the bean argument, with the given prefix.final ThisbindBeanList(String key, List<?> values, List<String> propertyNames) Bind a parameter for each value in the given list * number of property names, and defines an attribute as the comma-separated list of parameter references (using colon prefix).final ThisbindBinaryStream(int position, InputStream value, int length) Bind an argument positionallyfinal ThisbindBinaryStream(String name, InputStream value, int length) Bind an argument by namefinal ThisbindBySqlType(int position, Object value, int sqlType) Bind a value using a specific type fromjava.sql.Typesvia PreparedStatement#setObject(int, Object, int)final ThisbindBySqlType(String name, Object value, int sqlType) Bind a value using a specific type fromjava.sql.Typesvia PreparedStatement#setObject(int, Object, int)final ThisbindByType(int position, Object value, Type argumentType) Bind an argument dynamically by the type passed in.final ThisbindByType(int position, Object value, GenericType<?> argumentType) Bind an argument dynamically by the generic type passed in.final ThisbindByType(int position, Object value, QualifiedType<?> argumentType) Bind an argument dynamically by the qualified type passed in.final ThisbindByType(String name, Object value, Type argumentType) Bind an argument dynamically by the type passed in.final ThisbindByType(String name, Object value, GenericType<?> argumentType) Bind an argument dynamically by the generic type passed in.final ThisbindByType(String name, Object value, QualifiedType<?> argumentType) Bind an argument dynamically by the type passed in.bindFields(Object object) Binds public fields of the specified object as arguments for the query.bindFields(String prefix, Object object) Binds public fields of the specified object as arguments for the query.final Thisfinal Thisfinal Thisfinal ThisbindList(BiConsumer<SqlStatement, String> onEmpty, String key, Iterable<?> values) final ThisbindList(BiConsumer<SqlStatement, String> onEmpty, String key, Object... values) final ThisbindList(BiConsumer<SqlStatement, String> onEmpty, String key, Iterator<?> values) final ThisbindList(BiConsumer<SqlStatement, String> onEmpty, String key, List<?> values) Bind a parameter for each value in the given list, and defines an attribute as the comma-separated list of parameter references (using colon prefix).Binds named parameters from a map of String to Object instancesbindMethods(Object object) Binds methods with no parameters on the argument.bindMethods(String prefix, Object object) Binds methods with no parameters on the argument, with the given prefix.final ThisbindMethodsList(String key, Iterable<?> values, List<String> methodNames) For each value given, create a tuple by invoking each given method in order, and bind the tuple into aVALUES (...)format insert clause.bindNamedArgumentFinder(NamedArgumentFinder namedArgumentFinder) Binds a newNamedArgumentFinder.final ThisbindNull(int position, int sqlType) Bind NULL to be set for a given argument.final ThisBind NULL to be set for a given argument.final ThisbindNVarchar(int position, String value) Bind aStringargument positionally, asNVARCHARtype.final ThisbindNVarchar(String name, String value) Bind aStringargument by name, asNVARCHARtype.Binds named parameters from object properties on the argument.Binds named parameters from object properties on the argument.bindPojo(Object pojo, GenericType<?> type) Binds named parameters from object properties on the argument.Binds named parameters from object properties on the bean argument, with the given prefix.Binds named parameters from object properties on the bean argument, with the given prefix.bindPojo(String prefix, Object pojo, GenericType<?> type) Binds named parameters from object properties on the bean argument, with the given prefix.Transfer ownership of the handle to the statement: when the statement is closed, commit the handle's transaction (if one exists) and close the handle.When the statement is closed, roll it back then close the owning Handle.voidclose()final ThisdefineList(String key, Object... values) Define an attribute as the comma-separatedStringfrom the elements of thevaluesargument.final ThisdefineList(String key, List<?> values) Define an attribute as the comma-separatedStringfrom the elements of thevaluesargument.Define all bound arguments that don't already have a definition with a boolean indicating their presence.Returns the configuration registry associated with this object.final StatementContextReturns the statement context associated with this statement.final HandlesetQueryTimeout(int seconds) Set the query timeout, in seconds, on the prepared statement.toString()Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.jdbi.v3.core.config.Configurable
addCustomizer, 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, setTimingCollector
-
Method Details
-
setQueryTimeout
Set the query timeout, in seconds, on the prepared statement.- Parameters:
seconds- number of seconds before timing out- Returns:
- the same Query instance
-
cleanupHandleCommit
Transfer ownership of the handle to the statement: when the statement is closed, commit the handle's transaction (if one exists) and close the handle.- Returns:
- this
-
cleanupHandleRollback
When the statement is closed, roll it back then close the owning Handle.- Returns:
- this
-
bind
Used if you need to have some exotic parameter bound.- Parameters:
position- position to bindBinaryStream this argument, starting at 0argument- exotic argument factory- Returns:
- the same Query instance
-
bind
Used if you need to have some exotic parameter bound.- Parameters:
name- name to bindBinaryStream this argumentargument- exotic argument factory- Returns:
- the same Query instance
-
bindBean
Binds named parameters from JavaBean properties on the argument.- Parameters:
bean- source of named parameter values to use as arguments- Returns:
- modified statement
-
bindBean
Binds named parameters from JavaBean properties on the bean argument, with the given prefix. Example: the prefixfooapplied to a bean propertybarwill be bound asfoo.bar.- Parameters:
prefix- a prefix to apply to all property names.bean- source of named parameter values to use as arguments. Can be null, in this case, nothing is bound.- Returns:
- modified statement
-
bindPojo
Binds named parameters from object properties on the argument. The type must have been registered with pojo type mapping functionality first, usually by a plugin or configuration.- Parameters:
pojo- source of named parameter values to use as arguments- Returns:
- modified statement
- See Also:
-
bindPojo
Binds named parameters from object properties on the bean argument, with the given prefix. The type must have been registered with pojo type mapping functionality first, usually by a plugin or configuration.- Parameters:
prefix- a prefix to apply to all property names.pojo- source of named parameter values to use as arguments- Returns:
- modified statement
- See Also:
-
bindPojo
Binds named parameters from object properties on the argument. The type must have been registered with pojo type mapping functionality first, usually by a plugin or configuration.- Parameters:
pojo- source of named parameter values to use as argumentstype- the static, possibly generic type of the pojo- Returns:
- modified statement
- See Also:
-
bindPojo
Binds named parameters from object properties on the bean argument, with the given prefix. The type must have been registered with pojo type mapping functionality first, usually by a plugin or configuration.- Parameters:
prefix- a prefix to apply to all property names.pojo- source of named parameter values to use as argumentstype- the static, possibly generic type of the pojo- Returns:
- modified statement
- See Also:
-
bindPojo
Binds named parameters from object properties on the argument. The type must have been registered with pojo type mapping functionality first, usually by a plugin or configuration.- Parameters:
pojo- source of named parameter values to use as argumentstype- the static generic type of the pojo- Returns:
- modified statement
- See Also:
-
bindPojo
Binds named parameters from object properties on the bean argument, with the given prefix. The type must have been registered with pojo type mapping functionality first, usually by a plugin or configuration.- Parameters:
prefix- a prefix to apply to all property names.pojo- source of named parameter values to use as argumentstype- the static generic type of the pojo- Returns:
- modified statement
- See Also:
-
bindFields
Binds public fields of the specified object as arguments for the query.- Parameters:
object- source of the public fields to bind.- Returns:
- modified statement
-
bindFields
Binds public fields of the specified object as arguments for the query.- Parameters:
prefix- a prefix to apply to all field names.object- source of the public fields to bind. If the object is null, nothing is bound.- Returns:
- modified statement
-
bindMethods
Binds methods with no parameters on the argument.- Parameters:
object- source of methods to use as arguments- Returns:
- modified statement
-
bindMethods
Binds methods with no parameters on the argument, with the given prefix.- Parameters:
prefix- a prefix to apply to all property names.object- source of methods to use as arguments. If the object is null, nothing is bound.- Returns:
- modified statement
-
bindMap
Binds named parameters from a map of String to Object instances- Parameters:
map- map where keys are matched to named parameters in order to bind arguments. Can be null, in which case the binding has no effect.- Returns:
- modified statement
-
bindNamedArgumentFinder
Binds a newNamedArgumentFinder.- Parameters:
namedArgumentFinder- A NamedArgumentFinder to bind. Can be null.- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bindNVarchar
Bind aStringargument positionally, asNVARCHARtype.- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bindNVarchar
Bind aStringargument by name, asNVARCHARtype.- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bindASCIIStream
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bindlength- how long is the stream being bound?- Returns:
- the same Query instance
-
bindASCIIStream
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bindlength- bytes to read from value- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bindBinaryStream
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bindlength- the number of bytes in the stream.- Returns:
- the same Query instance
-
bindBinaryStream
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bindlength- bytes to read from value- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bindlength- number of characters to read- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bindlength- number of characters to read- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bind
Bind an argument positionally- Parameters:
position- position to bind the parameter at, starting at 0value- to bind- Returns:
- the same Query instance
-
bind
Bind an argument by name- Parameters:
name- token name to bind the parameter tovalue- to bind- Returns:
- the same Query instance
-
bindByType
Bind an argument dynamically by the type passed in.- Parameters:
position- position to bind the parameter at, starting at 0value- to bindargumentType- type for value argument- Returns:
- the same Query instance
-
bindByType
Bind an argument dynamically by the generic type passed in.- Parameters:
position- position to bind the parameter at, starting at 0value- to bindargumentType- type token for value argument- Returns:
- the same Query instance
-
bindByType
Bind an argument dynamically by the qualified type passed in.- Parameters:
position- position to bind the parameter at, starting at 0value- to bindargumentType- type token for value argument- Returns:
- the same Query instance
-
bindByType
Bind an argument dynamically by the type passed in.- Parameters:
name- token name to bind the parameter tovalue- to bindargumentType- type for value argument- Returns:
- the same Query instance
-
bindByType
Bind an argument dynamically by the generic type passed in.- Parameters:
name- token name to bind the parameter tovalue- to bindargumentType- type token for value argument- Returns:
- the same Query instance
-
bindByType
Bind an argument dynamically by the type passed in.- Parameters:
name- token name to bind the parameter tovalue- to bindargumentType- type for value argument- Returns:
- the same Query instance
-
bindArray
Bind a Java array as a SQL array. Usually you can justbind(int, Object)an array, but this method allows varargs.- Type Parameters:
T- the array element type- Parameters:
name- the name of the parameter to bindarray- the array to bind- Returns:
- this Query
-
bindArray
Bind a Java array as a SQL array. Usually you can justbind(int, Object)an array, but this method allows varargs.- Type Parameters:
T- the array element type- Parameters:
pos- the position of the parameter to bindarray- the array to bind- Returns:
- this Query
-
bindArray
Bind a Java array as a SQL array, casting each element to a new type.- Parameters:
name- the name of the parameter to bindelementType- the array element typearray- the array to bind- Returns:
- this Query
-
bindArray
Bind a Java array as a SQL array, casting each element to a new type.- Parameters:
pos- the position of the parameter to bindelementType- the array element typearray- the array to bind- Returns:
- this Query
-
bindArray
Bind an Iterable as a SQL array.- Parameters:
name- the name of the parameter to bindelementType- the element type of the Iterableiterable- the iterable to bind as an array- Returns:
- this Query
-
bindArray
Bind an Iterable as a SQL array.- Parameters:
pos- the position of the parameter to bindelementType- the element type of the Iterableiterable- the iterable to bind as an array- Returns:
- this Query
-
bindArray
Bind an Iterator as a SQL array.- Parameters:
name- the name of the parameter to bindelementType- the element type of the Iterableiterator- the iterator to bind as an array- Returns:
- this Query
-
bindArray
Bind an Iterator as a SQL array.- Parameters:
pos- the position of the parameter to bindelementType- the element type of the Iteratoriterator- the Iterator to bind as an array- Returns:
- this Query
-
bindNull
Bind NULL to be set for a given argument.- Parameters:
name- Named parameter to bind tosqlType- The sqlType must be set and is a value fromjava.sql.Types- Returns:
- the same statement instance
-
bindNull
Bind NULL to be set for a given argument.- Parameters:
position- position to bind NULL to, starting at 0sqlType- The sqlType must be set and is a value fromjava.sql.Types- Returns:
- the same statement instance
-
bindBySqlType
Bind a value using a specific type fromjava.sql.Typesvia PreparedStatement#setObject(int, Object, int)- Parameters:
name- Named parameter to bind atvalue- Value to bindsqlType- The sqlType from java.sql.Types- Returns:
- self
-
bindBySqlType
Bind a value using a specific type fromjava.sql.Typesvia PreparedStatement#setObject(int, Object, int)- Parameters:
position- position to bind NULL to, starting at 0value- Value to bindsqlType- The sqlType from java.sql.Types- Returns:
- self
-
bindList
- Parameters:
key- attribute namevalues- vararg values that will be comma-spliced into the defined attribute value.- Returns:
- this
- Throws:
IllegalArgumentException- if the vararg array is empty.- See Also:
-
bindList
- Parameters:
onEmpty- handler for null/empty vararg arraykey- attribute namevalues- vararg values that will be comma-spliced into the defined attribute value.- Returns:
- this
- Throws:
IllegalArgumentException- if the vararg array is empty.- See Also:
-
bindList
- Parameters:
key- attribute namevalues- iterable values that will be comma-spliced into the defined attribute value.- Returns:
- this
- Throws:
IllegalArgumentException- if the iterable is empty.- See Also:
-
bindList
- Parameters:
onEmpty- handler for null/empty listkey- attribute namevalues- iterable values that will be comma-spliced into the defined attribute value.- Returns:
- this
- Throws:
IllegalArgumentException- if the iterable is empty.- See Also:
-
bindList
- Parameters:
key- attribute namevalues- iterator of values that will be comma-spliced into the defined attribute value.- Returns:
- this
- Throws:
IllegalArgumentException- if the iterator is empty.- See Also:
-
bindList
- Parameters:
onEmpty- handler for null/empty listkey- attribute namevalues- iterator of values that will be comma-spliced into the defined attribute value.- Returns:
- this
- Throws:
IllegalArgumentException- if the iterator is empty.- See Also:
-
bindList
Bind a parameter for each value in the given list, and defines an attribute as the comma-separated list of parameter references (using colon prefix).Examples:
List<String> columnNames = Arrays.asList("id", "name", "created_on"); List<Object> values = Arrays.asList(1, "Alice", LocalDate.now()); handle.createUpdate("insert into things (<columnNames>) values (<values>)") .defineList("columnNames", columnNames) .bindList("values", values) .execute(); List<Integer> ids = Arrays.asList(1, 2, 3); List<Thing> things = handle.createQuery("select * from things where id in (<ids>)") .bindList("ids", ids) .mapTo(Contact.class) .list();Note that using this method modifies the SQL statement by using a defined attribute. This is problematic when usingHandle.prepareBatch(String)or thePreparedBatchSQL operation as those evaluate the SQL statement only once. When binding lists of different size, the number of placeholders will not match the number of elements in the list which will lead to errors.- Parameters:
onEmpty- handler for null/empty listkey- attribute namevalues- list of values that will be comma-spliced into the defined attribute value.- Returns:
- this
- Throws:
IllegalArgumentException- if the list is empty.- See Also:
-
bindBeanList
Bind a parameter for each value in the given list * number of property names, and defines an attribute as the comma-separated list of parameter references (using colon prefix). Used to create query similar to: select * from things where (id, foo) in ((1,'abc'),(2,'def'),(3,'ghi'))Examples:
List<ThingKey> thingKeys = ... List<Thing> things = handle.createQuery("select * from things where (id, foo) in (<thingKeys>)") .bindBeanList("thingKeys", thingKeys, Arrays.asList("id", "foo")) .mapTo(Contact.class) .list();- Parameters:
key- attribute namevalues- list of values that will be comma-spliced into the defined attribute value.propertyNames- list of properties that will be invoked on the values.- Returns:
- this
- Throws:
IllegalArgumentException- if the list of values or properties is empty.UnableToCreateStatementException- If a property can't be found on an value or we can't find a Argument for it.- See Also:
-
bindMethodsList
For each value given, create a tuple by invoking each given method in order, and bind the tuple into aVALUES (...)format insert clause.- Parameters:
key- attribute namevalues- list of values that will be comma-spliced into the defined attribute valuemethodNames- list of methods that will be invoked on the values- Returns:
- this
- Throws:
IllegalArgumentException- if the list of values or properties is empty.UnableToCreateStatementException- if the method cannot be found- See Also:
-
defineList
Define an attribute as the comma-separatedStringfrom the elements of thevaluesargument.Examples:
handle.createUpdate("insert into things (<columnNames>) values (<values>)") .defineList("columnNames", "id", "name", "created_on") .bindList("values", 1, "Alice", LocalDate.now()) .execute(); List<Thing> things = handle.createQuery("select <columnNames> from things") .bindList("columnNames", "id", "name", "created_on") .mapTo(Contact.class) .list();- Parameters:
key- attribute namevalues- vararg values that will be comma-spliced into the defined attribute value.- Returns:
- this
- Throws:
IllegalArgumentException- if the vararg array is empty, or contains any null elements.
-
defineList
Define an attribute as the comma-separatedStringfrom the elements of thevaluesargument.Examples:
List<String> columnNames = Arrays.asList("id", "name", "created_on"); List<Object> values = Arrays.asList(1, "Alice", LocalDate.now()); handle.createUpdate("insert into things (<columnNames>) values (<values>)") .defineList("columnNames", columnNames) .bindList("values", 1, values) .execute(); List<String> columnNames = Arrays.asList("id", "name", "created_on"); List<Thing> things = handle.createQuery("select <columnNames> from things") .bindList("columnNames", columnNames) .mapTo(Contact.class) .list();- Parameters:
key- attribute namevalues- list of values that will be comma-spliced into the defined attribute value.- Returns:
- this
- Throws:
IllegalArgumentException- if the list is empty, or contains any null elements.
-
defineNamedBindings
Define all bound arguments that don't already have a definition with a boolean indicating their presence. Useful to easily template optional properties of pojos or beans like<if(property)>property = :property<endif>.- Returns:
- this
-
toString
-
getHandle
-
getConfig
Description copied from interface:ConfigurableReturns the configuration registry associated with this object.- Specified by:
getConfigin interfaceConfigurable<This>- Returns:
- the configuration registry associated with this object.
-
getContext
Returns the statement context associated with this statement.- Returns:
- the statement context associated with this statement.
-
attachToHandleForCleanup
Registers 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
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-