由于“在准备执行报表查询的语句时出错",Jaspersoft Studio中生成报表时出错 [英] Error generating report in Jaspersoft Studio due to 'Error preparing statement for executing the report query'

查看:58
本文介绍了由于“在准备执行报表查询的语句时出错",Jaspersoft Studio中生成报表时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Jaspersoft Studio插件在Eclipse中生成多个jasper报告.

I am trying to generate several jasper reports in Eclipse using the Jaspersoft Studio plugin.

我有4个要传递的参数,我自己手动添加输入参数.

I have 4 parameters that will be passed in, and i am manually adding the input parameters myself.

运行预览时,由于

'Error preparing statement for executing the report query: 
SELECT rcia.inquirer.`First_Name`,
 rcia.inquirer.`Middle_Name`,
 rcia.inquirer.`Last_Name`,
 rcia.inquirer.`Father_Full_Name`,
 rcia.inquirer.`Mother_Full_Name`,
 rcia.inquirer.`Sponsor_First_Name`,
 rcia.inquirer.`Sponsor_Last_Name`,
FROM rcia.inquirer
WHERE 
 rcia.inquirer.`First_Name` = '$P{FirstName}' 
 AND rcia.inquirer.`Last_Name` = '$P{LastName}''

我不确定为什么会出现此错误.使用的是正确的SELECT查询吗?我传入参数FirstName和LastName,并使用它们选择数据库中的所有数据.

I am not sure why i am getting this error. Am using a correct SELECT query? I am passing in the parameter FirstName and LastName and using them to select all of the data in the database.

推荐答案

在jasper报告中执行查询时,您可以使用:

While executing query in jasper report you can use:

  1. 准备好的语句(避免sql注入),这是通过使用

  1. Prepared statement (avoid sql injection) this is achieved by using

$P{FirstName}

在这种情况下,查询必须没有限定符'

The query in this case need's to be without qualifier '

rcia.inquirer.`First_Name` = $P{FirstName} 

  • 字符串替换(作为@mkl注释)

  • String substitution (as @mkl comment)

    $P!{FirstName}
    

    在这种情况下,查询需要使用限定符(因为它是简单的字符串替换)

    The query in this case need's the qualifier (since its a simple string substitution)

    rcia.inquirer.`First_Name` = '$P!{FirstName}'
    

  • 首选方式是准备好的声明,主要是因为这将帮助您避免sql注入,但是如果 first 例如包含',它也将帮助您避免错误. Al'Capone 或其他可能破坏查询es的字符.\ ecc.

    The preferred way is Prepared statement mainly because this will help you to avoid sql injection, but also it will help you to avoid errors if the firstName for example contains ' es. Al'Capone, or other chars that could break your query es. \ ecc.

    这篇关于由于“在准备执行报表查询的语句时出错",Jaspersoft Studio中生成报表时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆