使用SQL命令表运行Crystal Report,从而提供Java中的条件值

时间:2012-01-31 15:58:31

标签: java crystal-reports crystal-reports-xi crystal-reports-export

我可以运行报告/以pdf格式导出报告来自eclipse的crystal report Java项目。此报告从SQL命令表中获取数据。

我需要帮助运行报告模板,在SQL命令表中使用“where condition”参数。

下面是我的代码,但不确定为什么创建的报告始终使用SQL命令中给出的相同默认值。

ReportClientDocument boReportClientDocument = new ReportClientDocument();
boReportClientDocument.setReportAppServer(com.crystaldecisions.sdk.occa.report.application.  ReportClientDocument.inprocConnectionString);

    boReportClientDocument.open("Cintron1.rpt", 0);
DatabaseController databaseController =   boReportClientDocument.getDatabaseController();
    com.crystaldecisions.sdk.occa.report.data.Tables tables = databaseController.getDatabase().getTables();

      //Set the datasource for all main report tables.
      for (int i = 0; i < tables.size(); i++)
      {

       com.crystaldecisions.sdk.occa.report.data.ITable table =  (com.crystaldecisions.sdk.occa.report.data.ITable) tables.getTable(i);
       if( table instanceof    com.crystaldecisions.sdk.occa.report.data.CommandTable){

       IProcedure command = (IProcedure)table;
       String commandtxt = command.toString();
       ParameterField commandParam = (ParameterField) command.getParameters().get(0);
           commandParam.getDescription();
           Values       values1=       commandParam.getCurrentValues();
           IValue val = values1.get(0);

            System.out.println("param field: "+commandParam.getDescription() +"value: "+val.computeText());
            Values values = new Values();
            ParameterFieldDiscreteValue pfdv = new ParameterFieldDiscreteValue();
            pfdv.setValue("6453");
            values.add(pfdv);
            commandParam.setCurrentValues(values);
            values1= commandParam.getCurrentValues();
            val = values1.get(0);
            System.out.println("param field after change: "+commandParam.getDescription() +"value: "+val.computeText());
     IConnectionInfo connectionInfo =   table.getConnectionInfo();
     connectionInfo.getAttributes();

       }
      }


boReportClientDocument.checkDatabaseAndUpdate();
    boolean isUpdated = boReportClientDocument.getIsModified();
boReportClientDocument.close();

    PrintOutputController printOutputController =
    boReportClientDocument.getPrintOutputController();
    ByteArrayInputStream byteIS = (ByteArrayInputStream)   printOutputController.export(ReportExportFormat.PDF);

        OutputStream out = new FileOutputStream("C:\\test123.pdf");

        // Transfer bytes from in to out
        byte[] buf = new byte[1024];
        int len;
        while ((len = byteIS.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        byteIS.close();
        out.close();

        }

0 个答案:

没有答案