在ireport中使用java表达式时执行sql语句时出错

时间:2015-02-25 05:05:24

标签: sql jasper-reports

我正在使用iReport进行报告开发。

我有2个参数,第一个参数(companyName)嵌入到第二个参数(pCompanyName)中。我也使用2个选项过滤参数。如果参数为null,则将打印出“”或空白,否则将打印查询。请参阅下面的参数部分。使用groovy语言时,它会打印出报告。

问题是将语言从groovy更改为java表达式后报表打印出错误。以下是错误。有人在这里请帮忙..绝望。

  

错误填充打印...错误执行的SQL语句为:laporan_quota   net.sf.jasperreports.engine.JRException:错误执行SQL语句:laporan_quota   在net.sf.jasperreports.engine.query.JRJdbcQueryExecuter.createDatasource(JRJdbcQueryExecuter.java:240)   在net.sf.jasperreports.engine.fill.JRFillDataset.createQueryDatasource(JRFillDataset.java:1114)   在net.sf.jasperreports.engine.fill.JRFillDataset.initDatasource(JRFillDataset.java:691)   在net.sf.jasperreports.engine.fill.JRBaseFiller.setParameters(JRBaseFiller.java:1314)   在net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:931)   在net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:873)   在net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:87)   在net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:287)   在net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:760)   在com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:891)   在org.openide.util.RequestProcessor $ Task.run(RequestProcessor.java:572)   在org.openide.util.RequestProcessor $ Processor.run(RequestProcessor.java:997)   java.sql.SQLSyntaxErrorException:ORA-00933:由造成SQL命令无法正常结束   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) )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)   在oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:53)   在oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:774)   在oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:925)   在oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1111)   在oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:4798)   在oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:4845)   在oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1501)   在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 {companyName}

2)$ P!{pCompanyName}

($P{companyName}.isEmpty() ? "" : " AND b.company_name = 'JA' ")

1 个答案:

答案 0 :(得分:0)

是的,最后我得到了上述问题的解决方案。

这是因为我没有把括号放在if else代码中,这就是为什么错误说sql语句错误但是我认为这不是sql语句错误,它语法错误:

<强>解决方案

更改此:( $ P {companyName} .isEmpty()?&#34;&#34;:&#34; AND b.company_name =&#39; JA&#39;&#34;)

对此:(($ P {companyName} .isEmpty())?&#34;&#34;:&#34; AND b.company_name =&#39; JA&#39;&#34;)