Pythorogus :
I have a function with a boolean parameter, but it could be null too.
If it's true or false, it makes a query with a "WHERE" clause. If it was null, the query has no "WHERE" clause, only the select clause.
How can I do that in Java ?
Roshana Pitigala :
Use Boolean
class
public String foo(Boolean addWhere){
String query = "SELECT * FROM tbl";
if(addWhere != null){
query += (addWhere? " WHERE true" : " WHERE false");
}
return query;
}
Call it as following,
String q = foo(false);