Hi,
I've got a function like this:
Now I want my string a little bit more dynamic. If a passed value is null, it should't be considered in the query.Code:public List getList(String a, String a, Date c) { String query = "from de.model.sap.Table1 t1 where t1.col1 = ? and t1.col2 = ? and t1.col3 = ?"; String obj[] = new String[3]; obj[0] = a; obj[0] = b; obj[0] = c; return this.getHibernateTemplate().find(query, obj); }
For example, if String a is null the query string only be:
"from de.model.sap.Table1 t1 where t1.col2 = ? and t1.col3 = ?"
Is there a way (or whatever) to achieve this, NOT creating this query/string by hand in a way like this:
Code:if(a=! null || b!= null || c != null){ query += " WHERE "; } ...
Thanks
Jonny


Reply With Quote