与Jaspersoft Studio的groovy和jdbc连接

时间:2014-07-29 15:41:13

标签: jdbc groovy jasper-reports jaspersoft-studio

我尝试将groovy用于我的报告,以将子数据集连接到Oracle数据库。

- >在报告中>性状>语言:groovy

- >在我的数据集中,我选择“使用其他连接”表达式:

Sql.newInstance(
                    "jdbc:oracle:thin:@ip:1521:XE",
                    "user",
                    "pw",
                    "oracle.jdbc.driver.OracleDriver"
                )

我的参数(ip,端口,用户,密码)是更正的,我已经做了这个java并且它可以工作但我需要用groovy做这个:(

当我预览报告时(使用groovy),我收到以下错误:

net.sf.jasperreports.engine.JRException: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression :
    Source text : Sql.newInstance(

                    "jdbc:oracle:thin:@ip:1521:XE",

                    "user",

                    "pw",

                    "oracle.jdbc.driver.OracleDriver"

                )

    at com.jaspersoft.studio.editor.preview.view.control.ReportControler.fillReport(ReportControler.java:466)

    at com.jaspersoft.studio.editor.preview.view.control.ReportControler.access$18(ReportControler.java:441)

    at com.jaspersoft.studio.editor.preview.view.control.ReportControler$4.run(ReportControler.java:333)

    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

Caused by: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression :
    Source text : Sql.newInstance(

                    "jdbc:oracle:thin:@ip:1521:XE",

                    "user",

                    "pw",

                    "oracle.jdbc.driver.OracleDriver"

                )

    at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:263)

    at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:611)

    at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:579)

    at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:1016)

    at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:392)

    at net.sf.jasperreports.components.table.fill.FillTableSubreport.evaluateSubreport(FillTableSubreport.java:92)

    at net.sf.jasperreports.components.table.fill.FillTable.evaluate(FillTable.java:118)

    at net.sf.jasperreports.engine.fill.JRFillComponentElement.evaluate(JRFillComponentElement.java:110)

    at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:259)

    at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:456)

    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2067)

    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:788)

    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:298)

    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:152)

    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:963)

    at net.sf.jasperreports.engine.fill.BaseFillHandle$ReportFiller.run(BaseFillHandle.java:120)

    at java.lang.Thread.run(Unknown Source)

Caused by: groovy.lang.MissingPropertyException: No such property: Sql for class: reportFacturation_1406640568882_851084

    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)

    at org.codehaus.groovy.runtime.callsite.GetEffectivePogoPropertySite.getProperty(GetEffectivePogoPropertySite.java:86)

    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)

    at reportFacturation_1406640568882_851084.evaluate(calculator_reportFacturation_1406640568882_851084:263)

    at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:250)

    ... 16 more

首先,感谢您的回复。

groovy.sql.Sql.newInstance("jdbc:oracle:thin:@ip:1521:XE", "user", "pw", "oracle.jdbc.driver.OracleDriver")

似乎是一个很好的表达:当我尝试使用groovyconsole.bat连接到我的数据库时,它会起作用。

但是我总是愿意从jasperstudio连接到我的oracle数据库,我不知道为什么。

我有ojdbc14-1.0.jar到我的构建路径(与java jdbc连接使用的jar相同,它正在工作)

我的groovy-sql-2.3.6.jar到我的构建路径(然后来自groovy的所有.jar因为我“无望”但它没有改变任何东西)

- >在报告中>性状>语言:groovy

- >在我的数据集中,我选择“使用其他连接”表达式:

groovy.sql.Sql.newInstance("jdbc:oracle:thin:@ip:1521:XE", "user", "pw", "oracle.jdbc.driver.OracleDriver")

它仍然不起作用我在预览后的“填充报告”阶段得到以下错误:

    net.sf.jasperreports.engine.JRException: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : 
    Source text : groovy.sql.Sql.newInstance("jdbc:oracle:thin:@ip:1521:XE", "user", "pw", "oracle.jdbc.driver.OracleDriver")

    at com.jaspersoft.studio.editor.preview.view.control.ReportControler.fillReport(ReportControler.java:466)

    at com.jaspersoft.studio.editor.preview.view.control.ReportControler.access$18(ReportControler.java:441)

    at com.jaspersoft.studio.editor.preview.view.control.ReportControler$4.run(ReportControler.java:333)

    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

Caused by: net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression : 
    Source text : groovy.sql.Sql.newInstance("jdbc:oracle:thin:@ip:1521:XE", "user", "pw", "oracle.jdbc.driver.OracleDriver")

    at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:263)

    at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:611)

    at net.sf.jasperreports.engine.fill.JRCalculator.evaluate(JRCalculator.java:579)

    at net.sf.jasperreports.engine.fill.JRFillElement.evaluateExpression(JRFillElement.java:1016)

    at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:392)

    at net.sf.jasperreports.components.table.fill.FillTableSubreport.evaluateSubreport(FillTableSubreport.java:92)

    at net.sf.jasperreports.components.table.fill.FillTable.evaluate(FillTable.java:118)

    at net.sf.jasperreports.engine.fill.JRFillComponentElement.evaluate(JRFillComponentElement.java:110)

    at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:259)

    at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:456)

    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:2067)

    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:788)

    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:298)

    at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:152)

    at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:963)

    at net.sf.jasperreports.engine.fill.BaseFillHandle$ReportFiller.run(BaseFillHandle.java:120)

    at java.lang.Thread.run(Unknown Source)

Caused by: java.sql.SQLException: No suitable driver found for jdbc:oracle:thin:@ip:1521:XE

    at java.sql.DriverManager.getConnection(Unknown Source)

    at java.sql.DriverManager.getConnection(Unknown Source)

    at groovy.sql.Sql.newInstance(Sql.java:398)

    at groovy.sql.Sql.newInstance(Sql.java:442)

    at groovy.sql.Sql$newInstance.call(Unknown Source)

    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)

    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)

    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)

    at reportFacturation_1406728137596_951810.evaluate(calculator_reportFacturation_1406728137596_951810:263)

    at net.sf.jasperreports.engine.fill.JREvaluator.evaluate(JREvaluator.java:250)

    ... 16 more

我也尝试使用“/ XE”,但它也不起作用。

我不知道我做错了什么,有什么想法吗?

感谢您的帮助! :)

1 个答案:

答案 0 :(得分:0)

替换它:

Sql.newInstance(
                "jdbc:oracle:thin:@ip:1521:XE",
                "user",
                "pw",
                "oracle.jdbc.driver.OracleDriver"
               )

用这个:

groovy.sql.Sql.newInstance("jdbc:oracle:thin:@ip:1521:XE", "user", "pw", 
        "oracle.jdbc.driver.OracleDriver")