1

我有我在我的摇摆应用程序上使用的这段代码:

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

4

1 回答 1

2

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

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

希望这可以帮助...

于 2012-05-18T03:49:14.920 回答