Запустите Crystal Report, используя таблицу команд SQL, где указаны значения условий из Java - PullRequest
1 голос
/ 31 января 2012

Я мог запустить отчет / экспортировать отчет в формате pdf из Crystal Reports Java проекта из eclipse. этот отчет получает данные из таблицы команд SQL.

Мне нужна помощь в запуске шаблона отчета с указанием параметров "где условие", используемых в таблице команд SQL.

Ниже приведен мой код, но я не уверен, почему создаваемый отчет всегда имеет те же значения по умолчанию, которые указаны в команде 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();

        }
...