11.4. Executing Queries
Prev | Chapter 11. Query | Next

## 11.4. Executing Queries

As evident from the examples above, queries are executed with one of the many `execute` methods defined in the `Query` interface. If your query declares between 0 and 3 parameters, use the `execute` version that takes the corresponding number of `Object` arguments; each argument should be set to a parameter value. For queries with more than 3 parameters, you can use the more generic `executeWithArray` and `executeWithMap` methods. See the `Query` interface Javadoc for details.

All `execute` methods declare a return type of `Object`, but they really return `Collection`s. The JDO specification only uses `Object` rather than `Collection` to enable vendors to use proprietary return types in certain cases, and to allow for future expansion of the interface.

Query results may hold on to data store resources; therefore, all results should be closed when they are no longer needed. You can close an individual query result with the `close` method, or all open results at once with the `closeAll`.

Prev | Up | Next
11.3. JDOQL | Home | 11.5. Query Compilation