Jump to content

Cannot call scriptlet method from SQL


bokucrow

Recommended Posts

Hello,

I've written a scriptlet class that returns a simple SQL query as a string:

package com.crow.Test;import net.sf.jasperreports.engine.JRDefaultScriptlet;import net.sf.jasperreports.engine.JRScriptletException;public class TestClass extends JRDefaultScriptlet {    public String TestMethod() throws JRScriptletException {        return "SELECT firstName FROM people LIMIT 10;";    }}[/code]

This string is then incorporated into the SQL query of my .jrxml report.

<?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.4.0.final using JasperReports Library version 6.4.1  -->...    <scriptlet name="Test" class="com.crow.Test.TestClass">        <scriptletDescription><![CDATA[]]></scriptletDescription>    </scriptlet>...    <queryString language="SQL">        <![CDATA[$P!{Test_SCRIPTLET}.TestMethod()]]>    </queryString>            <textField>                <textElement textAlignment="Right" verticalAlignment="Middle">                    <font size="12"/>                </textElement>                <textFieldExpression><![CDATA[$P{Test_SCRIPTLET}.TestMethod()]]></textFieldExpression>            </textField>...[/code]

However, the SQL (via $P!{Test_SCRIPTLET}.TestMethod()) fails with an exception of:

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'com.crow.Test.TestClass@12ebe8f.TestMethod' at line 1

I can confirm that the scriptlet is working as it should because its query is successfully displayed in a textbox if I suppress the query SQL or run the "One Empty Record" option. The exception only occurs if the SQL is issued to the DB.

Everything I've read so far indicates this config should work -- have I missed something?

Thanks in advance!

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...