Generating Statement programamtically

I am trying to create a Statement programatically, I have a number of filters I would like to apply to my query,
like so:

SELECT * FROM ‘bucketName’ WHERE param1=$param1Val AND param2=$param2Val… and so on

the thing is that these parameters may not always be passed, and I need my query to be able to handle that.

Is there a way to do this using the Java SDK?

Surprisingly I just tweeted about it today

I think this example is really great