我正在尝试从水晶报告文件中提取sql查询。我正在使用Eclipse for Crystal Reports来运行我的Java程序。我的文件使用ODBC连接到SQL Server 2008 R2来生成报告。我的源代码:
ReportClientDocument cRpt = new ReportClientDocument();
cRpt.open("C:\\Users\\jgou\\Desktop\\test\\myCR.rpt", 0);
if (cRpt.isOpen()) {
GroupPath gp = new GroupPath();
String crSql = null;
RowsetController rc = cRpt.getRowsetController();
String sqlStmt = rc.getSQLStatement(gp, null);
System.out.println("file is open");
System.out.println("crSql: " + crSql);
}
当我运行程序时,我收到以下错误:
com.crystaldecisions.sdk.occa.report.lib.ReportSDKException: Error finding JNDI name (TestDB)---- Error code:-2147467259 Error code name:failed
at com.businessobjects.reports.sdk.JRCCommunicationAdapter.a(SourceFile:2284)
at com.businessobjects.reports.sdk.JRCCommunicationAdapter.a(SourceFile:2304)
at com.businessobjects.reports.sdk.JRCCommunicationAdapter.if(SourceFile:736)
at com.businessobjects.reports.sdk.JRCCommunicationAdapter.a(SourceFile:166)
at com.businessobjects.reports.sdk.JRCCommunicationAdapter$2.a(SourceFile:528)
at com.businessobjects.reports.sdk.JRCCommunicationAdapter$2.call(SourceFile:526)
at com.crystaldecisions.reports.common.ThreadGuard.syncExecute(SourceFile:102)
at com.businessobjects.reports.sdk.JRCCommunicationAdapter.for(SourceFile:524)
at com.businessobjects.reports.sdk.JRCCommunicationAdapter.int(SourceFile:423)
at com.businessobjects.reports.sdk.JRCCommunicationAdapter.request(SourceFile:351)
at com.businessobjects.sdk.erom.jrc.a.a(SourceFile:54)
at com.businessobjects.sdk.erom.jrc.a.execute(SourceFile:67)
at com.crystaldecisions.proxy.remoteagent.RemoteAgent$a.execute(SourceFile:716)
at com.crystaldecisions.proxy.remoteagent.CommunicationChannel.a(SourceFile:125)
答案 0 :(得分:-1)
有关解决方案,请参阅以下链接。 http://www.javathinking.com/2011/09/using-crystal-reports-java-api-to.html
或者,您可以按如下方式传递数据
cRpt.getDatabaseController().setDataSource(list, tableName, tableName);
水晶报告不会搜索数据库,而是使用列表作为表格。 确保对报告使用的所有表格执行此操作。