Query Execution

When a query executes, the query filter is evaluated for each element of the candidate collection. Those instances that evaluate to true for the filter are included in the query result, which is a subset of the instances in the candidate collection. The query result should be cast to a Collection (execute( ) is declared to return an Object). You should then aquire an Iterator to access the instances in the result.

Parameter Declarations

When you execute a query, you often need to provide one or more values to be used in the query filter’s expressions. One technique is to generate the query filter string dynamically, providing the necessary values directly in the filter. But this approach does not allow the same query to be compiled and reused in subsequent query executions, which are likely to require the same filter expressions but with different values.

Query parameters allow you to specify such values dynamically when the query is executed. The parameter names are used in the filter expression to specify constraints. A parameter name can be used zero, one, or multiple times in the query filter. When you execute the query, each parameter must be provided a value; these values are substituted for each use of the parameter name in the filter. You can use parameters to minimize the need to construct a unique query filter dynamically each time you execute a query.

You need to declare a name and type for each query parameter. In addition, you may need to import the type ...

Get Java Data Objects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.