- All Superinterfaces:
Attachable,AttachableQueryPart,AutoCloseable,Query,QueryPart,Serializable,Statement
- All Known Subinterfaces:
CloseableResultQuery<R>
Query that holds a reference to the underlying
PreparedStatement without closing it, for reuse.
It was created via Query.keepStatement(boolean) and must be treated
as a resource, e.g. in a try-with-resources statement.
- Author:
- Lukas Eder
-
Method Summary
Modifier and TypeMethodDescription@NotNull CloseableQueryBind a new value to an indexed parameter.@NotNull CloseableQueryBind a new value to a named parameter.voidclose()Close the underlying statement.@NotNull CloseableQuerykeepStatement(boolean keepStatement) Keep the query's underlying statement open after execution.@NotNull CloseableQuerypoolable(boolean poolable) Specify whether any JDBCStatementcreated by this query should beStatement.setPoolable(boolean).@NotNull CloseableQueryqueryTimeout(int seconds) Specify the query timeout in number of seconds for the underlying JDBCStatement.Methods inherited from interface org.jooq.Attachable
attach, configuration, detachMethods inherited from interface org.jooq.AttachableQueryPart
getBindValues, getParam, getParams, getSQL, getSQLMethods inherited from interface org.jooq.Query
cancel, execute, executeAsync, executeAsync, isExecutable
-
Method Details
-
bind
@NotNull @NotNull CloseableQuery bind(String param, Object value) throws IllegalArgumentException, DataTypeException Description copied from interface:QueryBind a new value to a named parameter.[#1886] If the bind value with name
paramis inlined (Param.isInline()) or if this query was created withStatementType.STATIC_STATEMENTand there is an underlyingPreparedStatementkept open because ofQuery.keepStatement(boolean), the underlyingPreparedStatementwill be closed automatically in order for new bind values to have an effect.Performance consideration
Historically, the bind value is inserted into the mutable
Query, which means that theQueryneeds to be traversed in order to find the bind value and change it.As such, it is usually better to supply bind values directly with the input of an expression, e.g.:
- Directly with the
DSLmethod, such asDSL.log(Field, Field), for example. - With the plain SQL template constructor, e.g.
DSL.field(String, Object...) - With the parser method, e.g.
Parser.parseField(String, Object...)
- Specified by:
bindin interfaceQuery- Parameters:
param- The named parameter name. If this is a number, then this is the same as callingQuery.bind(int, Object)value- The new bind value.- Throws:
IllegalArgumentException- if there is no parameter by the given parameter name or index.DataTypeException- ifvaluecannot be converted into the parameter's data type
- Directly with the
-
bind
@NotNull @NotNull CloseableQuery bind(int index, Object value) throws IllegalArgumentException, DataTypeException Description copied from interface:QueryBind a new value to an indexed parameter.Bind index order
The 1-based parameter index describes a parameter in rendering order, not in input order. For example, if a query contains aDSL.log(Field, Field)call, where the first argument is thevalueand the second argument is thebase, this may produce different dialect specific renderings:- Db2:
ln(value) / ln(base) - Oracle:
log(base, value) - SQL Server:
log(value, base)
Some bind values may even be repeated by a dialect specific emulation, leading to duplication and index-shifting.
Performance consideration
Historically, the bind value is inserted into the mutable
Query, which means that theQueryneeds to be traversed in order to find the bind value and change it.As such, it is usually better to supply bind values directly with the input of an expression, e.g.:
- Directly with the
DSLmethod, such asDSL.log(Field, Field), for example. - With the plain SQL template constructor, e.g.
DSL.field(String, Object...) - With the parser method, e.g.
Parser.parseField(String, Object...)
Inlined values
[#1886] If the bind value at
indexis inlined (Param.isInline()) or if this query was created withStatementType.STATIC_STATEMENTand there is an underlyingPreparedStatementkept open because ofQuery.keepStatement(boolean), the underlyingPreparedStatementwill be closed automatically in order for new bind values to have an effect.- Specified by:
bindin interfaceQuery- Parameters:
index- The parameter index in rendering order, starting with 1value- The new bind value.- Throws:
IllegalArgumentException- if there is no parameter by the given parameter index.DataTypeException- ifvaluecannot be converted into the parameter's data type
- Db2:
-
poolable
Description copied from interface:QuerySpecify whether any JDBCStatementcreated by this query should beStatement.setPoolable(boolean).If this method is not called on jOOQ types, then jOOQ will not specify the flag on JDBC either, resulting in JDBC's default behaviour.
-
queryTimeout
Description copied from interface:QuerySpecify the query timeout in number of seconds for the underlying JDBCStatement.- Specified by:
queryTimeoutin interfaceQuery- See Also:
-
keepStatement
Description copied from interface:QueryKeep the query's underlying statement open after execution.This indicates to jOOQ that the query's underlying
StatementorPreparedStatementshould be kept open after execution. If it is kept open, client code is responsible for properly closing it usingclose(), e.g. via atry-with-resourcesstatement.- Specified by:
keepStatementin interfaceQuery- Parameters:
keepStatement- Whether to keep the underlying statement open
-
close
Close the underlying statement.This closes the query's underlying
StatementorPreparedStatementif a previous call tokeepStatement(boolean)indicated that jOOQ should keep statements open after query execution. If there is no underlying open statement, this call is simply ignored.- Specified by:
closein interfaceAutoCloseable- Throws:
DataAccessException- If something went wrong closing the statement- See Also:
-