在 ireport 中使用 java 表达式时执行 sql 语句时出错
Error executing sql statement when using java expression in ireport
我正在使用 iReport 进行报告开发。
我有 2 个参数,第一个参数 (companyName) 嵌入到第二个参数 (pCompanyName) 中。我还使用 2 个选项过滤参数。如果参数为空,它将打印出“”或空白,否则将打印查询。请参考下面的参数部分。使用groovy语言时,会打印出报告。
问题是在将语言从 groovy 更改为 java 表达式后报告打印出错误。下面是错误。有人在这里请帮助..绝望。
Error filling print... Error executing SQL statement for : laporan_quota
net.sf.jasperreports.engine.JRException: Error executing SQL statement for : laporan_quota
at net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.createDatasource(JRJdbcQueryExecuter.java:240)
at net.sf.jasperreports.engine.fill.JRFillDataset.createQueryDatasource(JRFillDataset.java:1114)
at net.sf.jasperreports.engine.fill.JRFillDataset.initDatasource(JRFillDataset.java:691)
at net.sf.jasperreports.engine.fill.JRBaseFiller.setParameters(JRBaseFiller.java:1314)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:931)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:873)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:87)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:287)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:760)
at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:891)
at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)
at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997)
Caused by: java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399) at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1059) at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:522) at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:257) at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:587) at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:225)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:53)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:774)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:925)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1111)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:4798)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:4845)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1501)
at net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.createDatasource(JRJdbcQueryExecuter.java:233)
Sql
SELECT DISTINCT
b.company_name company_name,
a.app_id permit_id,
b.quota_year,
b.app_id app_id,
g.descr ap_category,
h.descr ap_subcategory,
a.tariff_code hs_code,
h.descr model,
a.product_desc goods_description,
a.quantity quantity,
a.price_tot total_cost,
a.permit_no permit_no,
a.license_id license_no,
a.approved_date approve_date,
a.origin_country origin_country,
a.cnor_addr3 consignor_country,
a.branch_id miti_branch,
c.descr permit_status,
a.port_discharge port_name,
a.effect_date effective_date,
a.expiry_date expiry_date
FROM PERMIT_APP a, MT_PERMIT_APP_MASTER b, MT_REF_PERMIT_STATUS c, MT_QUOTA d, MT_QUOTA_APP e, MT_AP_TYPE f, MT_AP_CATEGORY g,
MT_AP_SUBCATEGORY h, MT_AP_TYPE_OPTION i
WHERE
a.master_app_id = b.app_id
AND b.quota_id = d.quota_id
AND d.quota_id = e.quota_id
AND f.ap_type_code = g.ap_type_code
AND g.ap_category_code = h.ap_category_code
AND h.ap_subcategory_code = b.ap_subcategory_code
AND f.ap_type_code = i.ap_type_code
AND a.status_code = c.status_code
AND c.status_code in ('102','301')
AND i.option_type = 'QUOTA'
$P!{pCompanyName}
参数
1) $P{公司名称}
2) $P!{pCompanyName}
($P{companyName}.isEmpty() ? "" : " AND b.company_name = 'JA' ")
是的,我终于得到了与我上面的问题相对应的解决方案。
这是因为我没有在 if else 代码中放入括号,这就是为什么错误说 sql 语句错误,但我认为它不是 sql 语句错误,它是语法错误:
解决方案
改变这个:( $P{companyName}.isEmpty( ) ? "" : " AND b.company_name = 'JA' ")
为此:( ($P{companyName}.isEmpty( ) ) ? "" : " AND b.company_name = 'JA' ")
我正在使用 iReport 进行报告开发。
我有 2 个参数,第一个参数 (companyName) 嵌入到第二个参数 (pCompanyName) 中。我还使用 2 个选项过滤参数。如果参数为空,它将打印出“”或空白,否则将打印查询。请参考下面的参数部分。使用groovy语言时,会打印出报告。
问题是在将语言从 groovy 更改为 java 表达式后报告打印出错误。下面是错误。有人在这里请帮助..绝望。
Error filling print... Error executing SQL statement for : laporan_quota net.sf.jasperreports.engine.JRException: Error executing SQL statement for : laporan_quota at net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.createDatasource(JRJdbcQueryExecuter.java:240) at net.sf.jasperreports.engine.fill.JRFillDataset.createQueryDatasource(JRFillDataset.java:1114) at net.sf.jasperreports.engine.fill.JRFillDataset.initDatasource(JRFillDataset.java:691) at net.sf.jasperreports.engine.fill.JRBaseFiller.setParameters(JRBaseFiller.java:1314) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:931) at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:873) at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:87) at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:287) at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:760) at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:891) at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572) at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997) Caused by: java.sql.SQLSyntaxErrorException: ORA-00933: SQL command not properly ended at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399) at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1059) at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:522) at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:257) at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:587) at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:225) at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:53) at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:774) at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:925) at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1111) at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:4798) at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:4845) at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1501) at net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.createDatasource(JRJdbcQueryExecuter.java:233)
Sql
SELECT DISTINCT
b.company_name company_name,
a.app_id permit_id,
b.quota_year,
b.app_id app_id,
g.descr ap_category,
h.descr ap_subcategory,
a.tariff_code hs_code,
h.descr model,
a.product_desc goods_description,
a.quantity quantity,
a.price_tot total_cost,
a.permit_no permit_no,
a.license_id license_no,
a.approved_date approve_date,
a.origin_country origin_country,
a.cnor_addr3 consignor_country,
a.branch_id miti_branch,
c.descr permit_status,
a.port_discharge port_name,
a.effect_date effective_date,
a.expiry_date expiry_date
FROM PERMIT_APP a, MT_PERMIT_APP_MASTER b, MT_REF_PERMIT_STATUS c, MT_QUOTA d, MT_QUOTA_APP e, MT_AP_TYPE f, MT_AP_CATEGORY g,
MT_AP_SUBCATEGORY h, MT_AP_TYPE_OPTION i
WHERE
a.master_app_id = b.app_id
AND b.quota_id = d.quota_id
AND d.quota_id = e.quota_id
AND f.ap_type_code = g.ap_type_code
AND g.ap_category_code = h.ap_category_code
AND h.ap_subcategory_code = b.ap_subcategory_code
AND f.ap_type_code = i.ap_type_code
AND a.status_code = c.status_code
AND c.status_code in ('102','301')
AND i.option_type = 'QUOTA'
$P!{pCompanyName}
参数
1) $P{公司名称}
2) $P!{pCompanyName}
($P{companyName}.isEmpty() ? "" : " AND b.company_name = 'JA' ")
是的,我终于得到了与我上面的问题相对应的解决方案。
这是因为我没有在 if else 代码中放入括号,这就是为什么错误说 sql 语句错误,但我认为它不是 sql 语句错误,它是语法错误:
解决方案
改变这个:( $P{companyName}.isEmpty( ) ? "" : " AND b.company_name = 'JA' ")
为此:( ($P{companyName}.isEmpty( ) ) ? "" : " AND b.company_name = 'JA' ")