Skip to main content

Queries

In addition to accessing Caché data through projections, a Java client can query the database. Caché supports several different ways to execute queries from within a Java client application.

Caché Query Type Characteristics Java Client Access
Class Queries Predefined SQL Queries declared within Caché class definitions. They resemble method declarations except that they contain SQL code.

The Java client uses a CacheQuery object's execute method. The method returns a java.sql.ResultSet object to the client.

The Java Projection for the class automatically contains a method, named query_<QueryName>, that can be used to retrieve an appropriately initialized CacheQuery object.

Alternatively, the Java client can create a new CacheQuery object using a constructor and initialize it using the name of the query.

Dynamic SQL SQL code created at runtime by the Java client.

Use the Database openByQuery method. The client passes the appropriate SQL string to the method. The method returns a java.util.Iterator object containing a set of opened objects.

Alternatively, pass the SQL string to Caché through CacheQuery. Caché returns a standard java.sql.ResultSet object to the client.

Embedded SQL SQL code contained inside Caché methods. Java client cannot access the SQL directly. However, using projections, the Java client may be able to access the method containing the SQL.
Note:

To learn more about Class Queries, read Class Queries in Using Caché Objects. To learn more about Dynamic SQL, read Using Dynamic SQL in Using Caché SQL. To learn more about Embedded SQL, read Using Embedded SQL in Using Caché SQL. To learn more about executing queries from within a Java client application, read the discussions of “Class Queries” and “Dynamic Queries” in the Using Queries section of Using Java with Caché.

FeedbackOpens in a new tab