Sejal,
You asked
Pls let me know how can acheive this?
That would depend on what database you are using. Oracle, for example, provides a feature called "native dynamic SQL".
Personally, I would probably write some stored procedure that takes (up to) eight parameters.
However, if you want it to be database independent, then I would put all the logic -- for building your query -- in your
java code.
Good Luck,
Avi.