JasperDesign actually lets you modify portions of your jrxml document. So say you have a package "reports" where you store your report built either by hand or by a tool like iReport. As long as your query is defined in the tag <queryString>
the following will work allowing you to change the query on the fly:
try {
String fileName = getClass().getClassLoader().getResource("com/foo/myproject/reports/TestReport.jrxml").getFile();
File theFile = new File(fileName);
JasperDesign jasperDesign = JRXmlLoader.load(theFile);
//Build a new query
String theQuery = "SLECT * FROM myTable WHERE ...";
// update the data query
JRDesignQuery newQuery = new JRDesignQuery();
newQuery.setText(theQuery);
jasperDesign.setQuery(newQuery);
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
Connection conn = MyDatabaseClass.getConnection();
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, conn);
JasperViewer.viewReport(jasperPrint);
} catch (Exception ex) {
String connectMsg = "Could not create the report " + ex.getMessage() + " " + ex.getLocalizedMessage();
System.out.println(connectMsg);
}
With something like this you can create a member variable of your class that holds the new query and build it with whatever user constrains desired. Then at view time just modify the design.
-Jeff