Top Description Methods
org.jooq

public Interface Query

extends Statement, AttachableQueryPart
Known Direct Subinterfaces
org.jooq.CloseableQuery, org.jooq.ResultQuery, org.jooq.RollbackToSavepointStep, org.jooq.impl.QOM.StartTransaction, org.jooq.impl.QOM.Savepoint, org.jooq.impl.QOM.ReleaseSavepoint, org.jooq.impl.QOM.Commit, org.jooq.impl.QOM.UEmptyQuery, org.jooq.RowCountQuery
Imports
java.sql.PreparedStatement, java.util.concurrent.CompletionStage, .Executor, org.jooq.conf.StatementType, org.jooq.exception.DataAccessException, .DataTypeException, org.jooq.impl.DSL, org.jetbrains.annotations.Blocking, .NotNull

Any query.

Instances can be created using DSL#query(String) and overloads, or by creating a subtype.

Author
Lukas Eder

Method Summary

Modifier and TypeMethod and Description
public @NotNull Query
bind(String
The named parameter name. If this is a number, then this is the same as calling bind(int, Object)
param
,
Object
The new bind value.
value
)

Bind a new value to a named parameter.

public @NotNull Query
bind(int
The parameter index, starting with 1
index
,
Object
The new bind value.
value
)

Bind a new value to an indexed parameter.

public void
cancel()

Cancel the underlying statement.

public int

Returns:

A result value, depending on the concrete implementation of Query:
  • Delete : the number of deleted records
  • Insert : the number of inserted records
  • Merge : the result may have no meaning
  • Select : the number of resulting records
  • Truncate : the result may have no meaning
  • Update : the number of updated records
execute
()

Execute the query, if it has been created with a proper configuration.

public @NotNull CompletionStage<Integer>

Returns:

A result value, depending on the concrete implementation of Query:
  • Delete : the number of deleted records
  • Insert : the number of inserted records
  • Merge : the result may have no meaning
  • Select : the number of resulting records
  • Truncate : the result may have no meaning
  • Update : the number of updated records
executeAsync
()

Execute the query in a new CompletionStage.

public @NotNull CompletionStage<Integer>

Returns:

A result value, depending on the concrete implementation of Query:
  • Delete : the number of deleted records
  • Insert : the number of inserted records
  • Merge : the result may have no meaning
  • Select : the number of resulting records
  • Truncate : the result may have no meaning
  • Update : the number of updated records
executeAsync
(Executor executor)

Execute the query in a new CompletionStage that is asynchronously completed by a task running in the given executor.

public boolean
isExecutable()

Whether this query is executable in its current state.

public @NotNull CloseableQuery
keepStatement(boolean
Whether to keep the underlying statement open
keepStatement
)

Keep the query's underlying statement open after execution.

public @NotNull Query
poolable(boolean poolable)

Specify whether any JDBC java.sql.Statement created by this query should be java.sql.Statement#setPoolable(boolean).

public @NotNull Query
queryTimeout(int seconds)

Specify the query timeout in number of seconds for the underlying JDBC Statement.

Inherited from org.jooq.AttachableQueryPart:
getBindValuesgetParamgetParamsgetSQLgetSQL

Method Detail

bindback to summary
public @NotNull Query bind(String param, Object value) throws IllegalArgumentException, DataTypeException

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.

Parameters
param:String

The named parameter name. If this is a number, then this is the same as calling bind(int, Object)

value:Object

The new bind value.

Annotations
@NotNull
Exceptions
IllegalArgumentException:
if there is no parameter by the given parameter name or index.
DataTypeException:
if value cannot be converted into the parameter's data type
bindback to summary
public @NotNull Query bind(int index, Object value) throws IllegalArgumentException, DataTypeException

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.

Parameters
index:int

The parameter index, starting with 1

value:Object

The new bind value.

Annotations
@NotNull
Exceptions
IllegalArgumentException:
if there is no parameter by the given parameter index.
DataTypeException:
if value cannot be converted into the parameter's data type
cancelback to summary
public void cancel() throws DataAccessException

Cancel the underlying statement.

This cancels the query's underlying Statement or PreparedStatement. If there is no underlying open and running statement, this call is simply ignored.

Exceptions
DataAccessException:
If something went wrong cancelling the statement
See Also
java.sql.Statement#cancel()
executeback to summary
public int execute() throws DataAccessException

Execute the query, if it has been created with a proper configuration.

Returns:int

A result value, depending on the concrete implementation of Query:

  • Delete : the number of deleted records
  • Insert : the number of inserted records
  • Merge : the result may have no meaning
  • Select : the number of resulting records
  • Truncate : the result may have no meaning
  • Update : the number of updated records
Annotations
@Blocking
Exceptions
DataAccessException:
If anything goes wrong in the database
executeAsyncback to summary
public @NotNull CompletionStage<Integer> executeAsync()

Execute the query in a new CompletionStage.

The result is asynchronously completed by a task running in an Executor provided by the underlying Configuration#executorProvider().

Returns:@NotNull CompletionStage<Integer>

A result value, depending on the concrete implementation of Query:

  • Delete : the number of deleted records
  • Insert : the number of inserted records
  • Merge : the result may have no meaning
  • Select : the number of resulting records
  • Truncate : the result may have no meaning
  • Update : the number of updated records
Annotations
@NotNull
executeAsyncback to summary
public @NotNull CompletionStage<Integer> executeAsync(Executor executor)

Execute the query in a new CompletionStage that is asynchronously completed by a task running in the given executor.

Returns:@NotNull CompletionStage<Integer>

A result value, depending on the concrete implementation of Query:

  • Delete : the number of deleted records
  • Insert : the number of inserted records
  • Merge : the result may have no meaning
  • Select : the number of resulting records
  • Truncate : the result may have no meaning
  • Update : the number of updated records
Annotations
@NotNull
isExecutableback to summary
public boolean isExecutable()

Whether this query is executable in its current state.

DML queries may be incomplete in structure and thus not executable. Calling execute() on such queries has no effect, but beware that getSQL() may not render valid SQL!

keepStatementback to summary
public @NotNull CloseableQuery 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. If it is kept open, client code is responsible for properly closing it using CloseableQuery#close(), e.g. via a try-with-resources statement.

Parameters
keepStatement:boolean

Whether to keep the underlying statement open

Annotations
@NotNull
poolableback to summary
public @NotNull Query poolable(boolean poolable)

Specify whether any JDBC java.sql.Statement created by this query should be java.sql.Statement#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.

Annotations
@NotNull
See Also
java.sql.Statement#setPoolable(boolean)
queryTimeoutback to summary
public @NotNull Query queryTimeout(int seconds)

Specify the query timeout in number of seconds for the underlying JDBC Statement.

Annotations
@NotNull
See Also
java.sql.Statement#setQueryTimeout(int)