I have a search page with multiple search criteria
etc
U
In such conditions I prefer adding 1=1 in where clause so that you dont have to keep track of where to insert AND.
String selectClause = "SELECT * FROM EMPLOYEES WHERE 1=1 ";
if(StringUtils.isNotBlank(empName)){
selectQuery += "AND EMP_NAME = " + empName;
}
if(StringUtils.isNotBlank(empID)){
selectQuery += "AND EMP_ID = " + empID;
}
//... and so on ...
Related question.