Error generating report in Jaspersoft Studio due to 'Error preparing statement for executing the report query'

我只是一个虾纸丫 提交于 2019-12-25 03:00:43

问题


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

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

When i run the preview it gives me Error generating report due to

'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}''

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.


回答1:


While executing query in jasper report you can use:

  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} 
    
  2. 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}'
    

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.



来源:https://stackoverflow.com/questions/33924022/error-generating-report-in-jaspersoft-studio-due-to-error-preparing-statement-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!