Jump to content
We've recently updated our Privacy Statement, available here ×

How to put a query into scriptlet?


federico.cattozzi

Recommended Posts

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...