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

标签 java swing jdbc crystal-reports crystal-reports-xi

我有在我的 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/

相关文章:

java - 检查 PreparedStatement 中的所有占位符是否已填充

java - Oracle SQL - 在通过 JDBC 调用的查询上重用绑定(bind)变量

java - Java 中已弃用的 JDBC 日期(java.sql 包)

java - apache poi从非常大的xls复制到新的工作簿表

java - 为什么 StringBuilder 表现得像引用传递

Java 二维数组 for 循环

java - 在 JPanel 中使文本跟随光标

java - 让我的 GUI 显示出来?

java - 创建一个带有多个复选框的组合框

java - 减少 JFrame 绘画中的延迟