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

New to iReport - How to count results


2004 IR Help

Recommended Posts

By: Helen - hjwb

New to iReport - How to count results

2004-03-22 20:41

Hi,

 

This is probably a very simple situation. I return a list of records from a SQL database (fields are strings). I just want to count the number of records returned. Can I do this - and if so, how?

 

Thanks,

Helen.

 

 

 

 

By: Alex Kotchnev - polrtex

RE: New to iReport - How to count results

2004-03-22 21:11

Helen,

one way you could do that would be to create a new counter variable (of type java.lang.Integer, initial value is new java.lang.Integer(0)) in iReport and set it to calculation type Count, and the varialbe expression is $F{field_name_to_count} (the name of the field from the db).

 

Yet another option would be to include something in your sql query, which will indicate how many records were returned e.g. if you query was :

select field1 from table1

you could have something like

select count(field1) as fieldCount, field1 from table1 ,

then you can access the field count by using $F{fieldCount} in iReport (if you register fieldCount as a field of course).

 

Hope this helps,

 

Alex K

 

 

 

 

By: Helen - hjwb

RE: New to iReport - How to count results

2004-03-23 20:59

Hi Alex,

 

Thanks for your help. I seem to be getting further now, but I'm still coming up with this error (using the first option you suggested):

 

dori.jasper.engine.JRException: Unable to get value for field 'fieldCount' of class 'java.lang.Integer'

 

at dori.jasper.engine.JRResultSetDataSource.getFieldValue(JRResultSetDataSource.java:272)

 

at dori.jasper.engine.fill.JRBaseFiller.next(JRBaseFiller.java:748)

 

at dori.jasper.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:163)

 

at dori.jasper.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:496)

 

at dori.jasper.engine.fill.JRFiller.fillReport(JRFiller.java:144)

 

at dori.jasper.engine.JasperFillManager.fillReport(JasperFillManager.java:350)

 

at dori.jasper.engine.JasperFillManager.fillReport(JasperFillManager.java:290)

 

at IReportCompiler.main(IReportCompiler.java:147)

 

Caused by: java.sql.SQLException: Column not found

 

at sun.jdbc.odbc.JdbcOdbcResultSet.findColumn(JdbcOdbcResultSet.java:1852)

 

at sun.jdbc.odbc.JdbcOdbcResultSet.getString(JdbcOdbcResultSet.java:413)

 

at dori.jasper.engine.JRResultSetDataSource.getFieldValue(JRResultSetDataSource.java:207)

 

... 7 more

 

 

 

 

 

 

By: Alex Kotchnev - polrtex

RE: New to iReport - How to count results

2004-03-24 02:09

Helen,

the error message appears to point to a problem of iReport not being to access a field by the name of fieldCount (so my guess is that you are trying to access $F{fieldCount }, rather, you should be trying to access the variable fieldCount, which will be by $V{fieldCount}. To accomplish that:

1. Go to the report variables, create a new variable, variable name fieldCount, initial value = new Integer(0), calculation Count. In the variable value put $F{sampleFieldNameFromTheDatabase}

2. On the report design, create a new text field, and in the field value, insert $V{fieldCount}.

 

I hope this helps.

 

Alex K

 

 

 

 

By: Helen - hjwb

RE: New to iReport - How to count results

2004-03-24 14:33

Thanks Alex, that worked wonderfully!

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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...