public interface Query extends QueryPart, Attachable
Modifier and Type | Method and Description |
---|---|
Query |
bind(int index,
Object value)
Bind a new value to an indexed parameter
[#1886] If the bind value at
index is inlined (
Param.isInline() ) or if this query was created with
StatementType.STATIC_STATEMENT and there is an underlying
PreparedStatement kept open because of
keepStatement(boolean) , the underlying
PreparedStatement will be closed automatically in order for
new bind values to have an effect. |
Query |
bind(String param,
Object value)
Bind a new value to a named parameter
[#1886] If the bind value with name
param is inlined (
Param.isInline() ) or if this query was created with
StatementType.STATIC_STATEMENT and there is an underlying
PreparedStatement kept open because of
keepStatement(boolean) , the underlying
PreparedStatement will be closed automatically in order for
new bind values to have an effect. |
void |
cancel()
Cancel the underlying statement
This cancels the query's underlying
Statement or
PreparedStatement . |
void |
close()
Close the underlying statement
This closes the query's underlying
Statement or
PreparedStatement if a previous call to
keepStatement(boolean) indicated that jOOQ should keep
statements open after query execution. |
int |
execute()
Execute the query, if it has been created with a properly configured
factory
|
List<Object> |
getBindValues()
Retrieve the bind values that will be bound by this Query.
|
Param<?> |
getParam(String name)
Get a named parameter from the
Query , provided its name. |
Map<String,Param<?>> |
getParams()
Get a
Map of named parameters. |
String |
getSQL()
Retrieve the SQL code rendered by this Query
This method can be expected to work correctly for any SQL dialect, as a
query is usually "attached" when created from a
DSLContext . |
String |
getSQL(boolean inline)
Retrieve the SQL code rendered by this Query
See
getSQL() for more details |
boolean |
isExecutable()
Whether this query is executable in its current state
DML queries may be incomplete in structure and thus not executable.
|
Query |
keepStatement(boolean keepStatement)
Keep the query's underlying statement open after execution
This indicates to jOOQ that the query's underlying
Statement or
PreparedStatement should be kept open after execution. |
Query |
queryTimeout(int timeout)
Specify the query timeout for the underlying JDBC
Statement |
attach
int execute() throws DataAccessException
Query
:
DataAccessException
- If anything goes wrong in the databaseboolean isExecutable()
String getSQL()
This method can be expected to work correctly for any SQL dialect, as a
query is usually "attached" when created from a DSLContext
.
Use this method, when you want to use jOOQ for object oriented query creation, but execute the query with some other technology, such as
Note, this is the same as calling getSQL(boolean)
. The boolean
parameter will depend on your DSLContext
's Settings
:
StatementType |
boolean parameter | effect |
---|---|---|
StatementType.PREPARED_STATEMENT |
false (default) |
This will render bind variables to be used with a JDBC
PreparedStatement . You can extract bind values from this
Query using getBindValues() |
StatementType.STATIC_STATEMENT |
true |
This will inline all bind variables in a statement to be used with a
JDBC Statement |
getSQL(boolean)
String getSQL(boolean inline)
See getSQL()
for more details
inline
- Whether to inline bind variables. This overrides values in
Settings.getStatementType()
List<Object> getBindValues()
List
cannot be modified. To modify bind values, use
getParams()
instead.Map<String,Param<?>> getParams()
Map
of named parameters. The Map
itself
cannot be modified, but the Param
elements allow for modifying
bind values on an existing Query
.
Bind values created with DSL.val(Object)
will have their bind
index as name.
Param<?> getParam(String name)
Query
, provided its name.
Bind values created with DSL.val(Object)
will have their bind
index as name.
Query bind(String param, Object value) throws IllegalArgumentException, DataTypeException
[#1886] If the bind value with name param
is inlined (
Param.isInline()
) or if this query was created with
StatementType.STATIC_STATEMENT
and there is an underlying
PreparedStatement
kept open because of
keepStatement(boolean)
, the underlying
PreparedStatement
will be closed automatically in order for
new bind values to have an effect.
param
- The named parameter name. If this is a number, then this is
the same as calling bind(int, Object)
value
- The new bind value.IllegalArgumentException
- if there is no parameter by the given
parameter name or index.DataTypeException
- if value
cannot be converted into
the parameter's data typeQuery bind(int index, Object value) throws IllegalArgumentException, DataTypeException
[#1886] If the bind value at index
is inlined (
Param.isInline()
) or if this query was created with
StatementType.STATIC_STATEMENT
and there is an underlying
PreparedStatement
kept open because of
keepStatement(boolean)
, the underlying
PreparedStatement
will be closed automatically in order for
new bind values to have an effect.
index
- The parameter index, starting with 1value
- The new bind value.IllegalArgumentException
- if there is no parameter by the given
parameter index.DataTypeException
- if value
cannot be converted into
the parameter's data typeQuery queryTimeout(int timeout)
Statement
Statement.setQueryTimeout(int)
Query keepStatement(boolean keepStatement)
This indicates to jOOQ that the query's underlying Statement
or
PreparedStatement
should be kept open after execution. If it is
kept open, client code is responsible for properly closing it using
close()
keepStatement
- Whether to keep the underlying statement openvoid close() throws DataAccessException
This closes the query's underlying Statement
or
PreparedStatement
if a previous call to
keepStatement(boolean)
indicated that jOOQ should keep
statements open after query execution. If there is no underlying open
statement, this call is simply ignored.
DataAccessException
- If something went wrong closing the statementStatement.close()
void cancel() throws DataAccessException
This cancels the query's underlying Statement
or
PreparedStatement
. If there is no underlying open and running
statement, this call is simply ignored.
DataAccessException
- If something went wrong cancelling the
statementStatement.cancel()
Copyright © 2013. All Rights Reserved.