2006 IR Open Dicussion Posted August 16, 2006 Share Posted August 16, 2006 By: Curtis Greg W - cgregjam How to pass parameter from a java application 2002-09-03 11:55 Can any one tell me how to pass parameter from a java application to jasper report or how to modify the select statement dynamically Thanks. By: Louis W. Lembcke - llembcke RE: How to pass parameter from a java application 2002-09-03 18:17 In your java program, you can execute (aka fill) the report using the dori.jasper.engine.JasperFillManager. This class has several static convenience methods to facilitate executing the report. These methods take, among other things, a Map object. The Map object is used to pass parameters into the report where the Map entry key is the String name of the parameter and the corresponding Map entry value is the object containing the value. The value object must be of the same type as what you declared in your <param name="..." class="..."/> tag in your report definition. You can modify the SQL statement dynamically by using those parameter values similar to normal substituted values in any prepared query. The syntax to reference a parameter value is $P{param-name}. For example... In the java of the report launcher/driver... ... java.sql.Connection dbConn = ... java.util.Map params = new java.util.HashMap(); params.put( "skippy", new Integer(42) ); JasperPrint prnt = JasperFillManager.fillReport( reportFilePath, params, dbConn ); ... In the report definition... ... <parameter name="skippy" class="java.lang.Integer" /> ... <queryString><![CDATA[ SELECT * FROM someTable WHERE someColumn = $P{skippy} ]]></queryString> Of course, your report launcher/driver can get the values for the parameters from a variety of sources: command line arguments, system properties, properties file, other xml files, database queries, jndi lookups, hard-coded, etc. Study the tutorial write-up and sample report definitions for more information. By: Curtis Greg W - cgregjam RE: How to pass parameter from a java application 2002-09-04 05:14 Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now