如何将我的 java swing 应用程序的连接传递到 Crystal Reports XI?

Posted

技术标签:

【中文标题】如何将我的 java swing 应用程序的连接传递到 Crystal Reports XI?【英文标题】:How to pass connection from my java swing application to Crystal Reports XI? 【发布时间】:2012-05-18 02:55:27 【问题描述】:

我在我的摇摆应用程序中使用了这段代码:

    ReportClientDocument rpt =  new ReportClientDocument();
    rpt.open(reportPath+"APVendorList.rpt", 0);
    rpt.getReportSource();


    ReportViewerBean viewer = new ReportViewerBean();
    viewer.init(new String[0], null, null, null);
    //viewer.setHasGroupTree(false);
    viewer.setReportSource(rpt.getReportSource());

问题是每当我尝试使用 jframe 加载报告时,它总是要求提供登录凭据:

Database Logon:
Server Name: Localhost
Database Name: <blank and cannot be edited>
User ID:
Password:

有没有办法在我查看报告时不输入这些信息?或者我可以将 java.sql.Connection 传递给它?此外,它似乎不知道要连接到哪个数据库。请帮忙。

【问题讨论】:

“如何将连接从我的 java swing 应用程序传递到 Crystal Reports XI?” 可能与您从命令行执行此操作的方式相同。 Swing 与此有什么关系? 糟糕!对不起,误导性的标题。我想应该是“如何将连接从我的 java swing 应用程序传递到我的水晶报表”? 相同的 cmets 适用于建议的更改标题。另请注意,它是 Java 和 Swing,而不是 Java 和 Swing。 抱歉这个错误。我希望你的cmets可以回答我的问题。 :( 【参考方案1】:

您可以设置属性值,如下所示:

ReportClientDocument clientDoc = new ReportClientDocument();
....
DatabaseController dbController=clientDoc.getDatabaseController();
IConnectionInfo ConnInfo = dbController.getConnectionInfos(null).getConnectionInfo(0);
com.crystaldecisions.sdk.occa.report.lib.PropertyBag boPropertyBag1 = new com.crystaldecisions.sdk.occa.report.lib.PropertyBag();
// Set the properties for the connection
boPropertyBag1.put("JDBC Connection String", connString);
boPropertyBag1.put("Database Class Name", dbClassName);
boPropertyBag1.put("Connection URL", connString);
boPropertyBag1.put("Server", serverHost);
....
// Assign the properties to the connection info
ConnInfo.setAttributes(boPropertyBag1);
// Set the DB Username and Pwd
ConnInfo.setUserName(usrName);
ConnInfo.setPassword(pwd);

希望这会有所帮助...

【讨论】:

感谢您的回答。我尝试了该代码并且它工作了一次。第一次运行后我收到一条错误消息:com.crystaldecisions.sdk.occa.report.lib.ReportSDKServerException:没有指定服务器。----错误代码:-2147217390 错误代码名称:serverNotFound Btw 检查类后得到了一个简单的解决方案,它确实有效。 ReportClientDocument rpt = new ReportClientDocument(); rpt.open(reportPath+"Contact.rpt", 0); rpt.getDatabaseController().logon("用户名", "密码");这是正确的吗?我不知道那个简单代码的后果。

以上是关于如何将我的 java swing 应用程序的连接传递到 Crystal Reports XI?的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Swing jframe 中嵌入 SWT 浏览器

如何将我的函数的参数传递给 mvrnorm?

javaswing如何连接服务器

如何在 JFrame/JPanel 中可视化控制台 java

如何让 Swing 将我自己的 HTMLEditorKit 用于 JLabel/JButton/等

将字体导入java(不使用Swing)