Module org.jooq
Package org.jooq

Interface Query

    • Method Detail

      • execute

        int execute()
             throws DataAccessException
        Execute the query, if it has been created with a proper configuration.
        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
        Throws:
        DataAccessException - If anything goes wrong in the database
      • executeAsync

        @NotNull
        @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:
        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
      • isExecutable

        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!

      • getSQL

        @NotNull
        @NotNull String getSQL()
        Retrieve the SQL code rendered by this Query.

        Use this method, when you want to use jOOQ for object oriented query creation, but execute the query with some other technology, such as

        • JDBC
        • Spring Templates
        • JPA native queries
        • etc...

        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

        [#1520] Note that the query actually being executed might not contain any bind variables, in case the number of bind variables exceeds your SQL dialect's maximum number of supported bind variables. This is not reflected by this method, which will only use the Settings to decide whether to render bind values.

        See Also:
        getSQL(boolean)
      • getSQL

        @NotNull
        @Deprecated
        @NotNull String getSQL​(boolean inline)
        Deprecated.
        - [#2414] - 3.1.0 - Use getSQL(ParamType) instead
        Retrieve the SQL code rendered by this Query.

        [#1520] Note that the query actually being executed might not contain any bind variables, in case the number of bind variables exceeds your SQL dialect's maximum number of supported bind variables. This is not reflected by this method, which will only use inline argument to decide whether to render bind values.

        See getSQL() for more details.

        Parameters:
        inline - Whether to inline bind variables. This overrides values in Settings.getStatementType()
        Returns:
        The generated SQL
      • getSQL

        @NotNull
        @NotNull String getSQL​(ParamType paramType)
        Retrieve the SQL code rendered by this Query.

        [#1520] Note that the query actually being executed might not contain any bind variables, in case the number of bind variables exceeds your SQL dialect's maximum number of supported bind variables. This is not reflected by this method, which will only use paramType argument to decide whether to render bind values.

        See getSQL() for more details.

        Parameters:
        paramType - How to render parameters. This overrides values in Settings.getStatementType()
        Returns:
        The generated SQL
      • getBindValues

        @NotNull
        @NotNull List<Object> getBindValues()
        Retrieve the bind values that will be bound by this Query. This List cannot be modified. To modify bind values, use getParams() instead.

        Unlike getParams(), which returns also inlined parameters, this returns only actual bind values that will render an actual bind value as a question mark "?"

        See Also:
        DSLContext.extractBindValues(QueryPart)
      • keepStatement

        @NotNull
        @NotNull 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. If it is kept open, client code is responsible for properly closing it using close()

        Parameters:
        keepStatement - Whether to keep the underlying statement open