You have to take care of a few things:
1) You have to declare a text-parameter called "query-name", of course
2) You have to set the formula "=[query-name]" on the query::name attribute of the master-report. (Hit the green "+" for the expression/formula-editor)
3) You have to add the "JDBC (Custom)" datasource and configure your connection
4) Your query has to return the same field names every time, or the report-field will not find the fields they were looking for.
If you want to absolutely dynamic, look at that sample (Help->Welcome; and then under the "Advanced" section on the right hand side), the master-report has a report-pre-processor defined.
http://wiki.pentaho.com/display/Repo...orIntroduction
BTW: Generally it is a very bad idea to get a query directly from the outside world. Users can do rather nasty things with that, like getting all your data out of your database, including the super secret stuff that no one (especially the SEC or the IRS) should ever see.