gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 04:47:27 25 4
gpt4 key购买 nike

我有在我的 swing 应用程序中使用的代码:

    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 传递给它?而且它似乎不知道要连接到哪个数据库。请帮忙。

最佳答案

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

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);

希望这有帮助...

关于java - 如何将我的 java swing 应用程序的连接传递到 Crystal Reports XI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10646135/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com