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

时间:2012-05-18 02:55:28

标签: 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:

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

1 个答案:

答案 0 :(得分: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);

希望这会有所帮助......