Simple JDBC Query By Example (QBE) for Spring JDBC Template
Be careful of SQL injections.

Assuming that the Order object is sanitized, then the only suggestion I'd make is to make a class for your order query and extract the logic from your method into that class.

A quick example would be that:

public class OrderQuery {

    private List&lt;String&gt; clauses = new ArrayList&lt;&gt;();
    private List&lt;Object&gt; values = new ArrayList&lt;&gt;();

    public OrderQuery(Order order) {
        setOrderId(order.getOrderID());
        // ...
    }

    private void setOrderId(String orderId) {
        if (orderId != null) {
            clauses.add("order_id = ?");
            values.add(orderId);
        }
    }

    // ...

    public List&lt;Object&gt; getValues() {
        return values;
    }

    @Override
    public String toString() {
        StringBuilder sql = new StringBuilder();
        sql.append("select * from orders ");
        if (!clauses.isEmpty()) {
            sql.append("where ");
        }
        String whereClause = clauses.stream().collect(Collectors.joining(" and "));
        sql.append(whereClause);
        return sql.toString()
    }
}


And to call it from your now much less clustered method: 

public List&lt;Order&gt; orderQuery(Order order) {
    OrderQuery orderQuery = new OrderQuery(order)
    List&lt;Order&gt; result = jdbcTemplate.query(orderQuery.toString(), orderRowMapper, orderQuery.getValues().toArray());
    return result;
}


But it could be further optimized by using something like builder pattern.