SQL prepared statement how to select via multiple possible menu selections?

前端 未结 2 1424

So I have 4 menu selections (product, location, courseType, and category), all of which can be null (programmed using JSF but that should be irrelevant to this question, as

2条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 14:23

    I tend to build dynamic queries with helper methods like this:

    StringBuilder query = new StringBuidler();
    query.append("SELECT foo, bar FROM baz");
    query.append(buildProductClause(product));
    query.append(buildLocationClause(location));
    query.append(buildCourseTypeClause(courseType));
    // etc...
    

    You could use a member field to build an array of arguments if you want to still use a prepared statement.

提交回复
热议问题