Skip Headers

# Using Java

Previous

Next

To create an expression in Java code, use the `Expression` class or `ExpressionBuilder` method `get`.

The `ExpressionBuilder` acts as a substitute for the objects that you query. To construct a query, call methods on the `ExpressionBuilder` that correspond to the attributes of the objects. We recommend that you name `ExpressionBuilder` objects according to the type of objects against which you do a query.

Note: An instance of `ExpressionBuilder` is specific to a particular query. Do not attempt to build another query using an existing builder, because it still contains information related to the first query.

Example: Using ExpressionBuilder to Build a Simple Expression illustrates how to use the query key `lastName` to reference the field name L_NAME.

Using ExpressionBuilder to Build a Simple Expression

    Expression expression = new ExpressionBuilder().get("lastName").equal("Young");

Example: Combining Two Expressions with a Logical AND Operator illustrates how to create a complex expression by combining two smaller expressions with a logical `and` operator.

Combining Two Expressions with a Logical AND Operator

    ExpressionBuilder emp = new ExpressionBuilder();
        Expression exp1, exp2;
        exp1 = emp.get("firstName").equal("Ken");
        exp2 = emp.get("lastName").equal("Young");
        return exp1.and(exp2);

Example: Using Database Function notLike in an Expression illustrates how to create an expression using the `notLike` operator.

Using Database Function notLike in an Expression

    Expression expression = new ExpressionBuilder().get("lastName").notLike("%ung");