How to set Parameters for a Query

0

I am very new to Jasper Reports .

I am trying to create a Report in Jasper studio by passing some parameters to it .

When I pass the parameters to the query an excwption is shown in the .

I have put the Query and  Exception I got while setting up the report.

Main Exception

Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0).

Query

SELECT COUNT( id)
FROM `employee`
WHERE
  'SIGNEDUP_ON' > '$P{From Date}' 
  AND 'SIGNEDUP_ON' < ' $P{To Date} '

Exception

net.sf.jasperreports.engine.JRException: Error preparing statement for executing the report query:
SELECT Count( id)FROM `employee`WHERE   'SIGNEDUP_ON' > '?'    AND 'SIGNEDUP_ON' < ' ? '
 
at net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.createStatement(JRJdbcQueryExecuter.java:520) at net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.createDatasource(JRJdbcQueryExecuter.java:297) at com.jaspersoft.studio.data.jdbc.JDBCFieldsProvider.getFields(JDBCFieldsProvider.java:79) at com.jaspersoft.studio.data.jdbc.JDBCDataAdapterDescriptor.getFields(JDBCDataAdapterDescriptor.java:75) at com.jaspersoft.studio.property.dataset.dialog.DataQueryAdapters.doGetFields(DataQueryAdapters.java:396) at com.jaspersoft.studio.data.designer.AQueryDesignerContainer$1.run(AQueryDesignerContainer.java:53) at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)Caused by: java.sql.SQLException: Parameter index out of range (1 > number of parameters, which is 0). at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860) at com.mysql.jdbc.PreparedStatement.checkBounds(PreparedStatement.java:3327) at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3312) at com.mysql.jdbc.PreparedStatement.setInternal(PreparedStatement.java:3351) at com.mysql.jdbc.PreparedStatement.setDate(PreparedStatement.java:3237) at com.mysql.jdbc.PreparedStatement.setDate(PreparedStatement.java:3205) at net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.setDate(JRJdbcQueryExecuter.java:858) at net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.setStatementParameter(JRJdbcQueryExecuter.java:756) at net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.setStatementParameter(JRJdbcQueryExecuter.java:572) at net.sf.jasperreports.engine.query.JRJdbcQueryExecuter$1.visit(JRJdbcQueryExecuter.java:480) at net.sf.jasperreports.engine.query.JRAbstractQueryExecuter$QueryParameter.accept(JRAbstractQueryExecuter.java:163) at net.sf.jasperreports.engine.query.JRAbstractQueryExecuter.visitQueryParameters(JRAbstractQueryExecuter.java:666) at net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.createStatement(JRJdbcQueryExecuter.java:465) ... 6 more

spencer.bharath's picture
Joined: May 8 2017 - 9:08am
Last seen: 2 years 2 months ago

1 Answer:

0

Try with:

SELECT COUNT( id)
FROM `Interns`
WHERE
  'SIGNEDUP_ON' > $P{From Date}
  AND 'SIGNEDUP_ON' < $P{To Date}

Or better:

SELECT COUNT( id)
FROM `Interns`
WHERE $X{[BETWEEN], 'SIGNEDUP_ON', From_Date, To_Date}

I don't remember if Jaspersoft allow parameter names with spaces.

Mariano

mlopez_1's picture
909
Joined: Oct 21 2013 - 8:08am
Last seen: 1 week 2 days ago
Feedback