federico.cattozzi Posted March 7, 2012 Share Posted March 7, 2012 Hi,I want to put a SQL query into a scriptlet to set a default value for a parameter.What is the correct way?Thanks. Link to comment Share on other sites More sharing options...
federico.cattozzi Posted March 12, 2012 Author Share Posted March 12, 2012 I answer to myself.An example:Code:public class MyJRDefaultScriptlet extends net.sf.jasperreports.engine.JRDefaultScriptlet {} public int getMaxValue(String s) throws JRScriptletException, SQLException{ Connection con = ((Connection)this.getParameterValue(JRParameter.REPORT_CONNECTION)); Statement stmt = null; String query = "SELECT max(foo.value) FROM foo WHERE foo.s = '" + s + "'"; int max = 0; try { stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { max = rs.getInt("value"); } } catch (SQLException e ) { } finally { if (stmt != null) { stmt.close(); } } return max; }} 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