cancel
Showing results for 
Search instead for 
Did you mean: 

Crystal Reports SDK \ Report with XML Datasource doesn't refresh data in WebApp

Former Member
0 Kudos

Crystal Reports SDK \ Report with XML Datasource doesn't refresh data in WebApp

Good afternoon!

I'm trying to render a Crystal Report with a XML Datasource using the Java Runtime SDK for Crystal.

In the Crystal Reports XI App when I refresh the Parameters it reloads with new data, but when I do the same action in the WebApp  (Typing new data into parameters), the report loads the same data everytime.

This is my full code.

/************* CODE **************/

<%@page contentType="text/html"%>

<%@page pageEncoding="UTF-8"%>

<% //Crystal Java Reporting Component (JRC) imports.%>

<%@page import="com.crystaldecisions.sdk.occa.report.reportsource.*" %>

<%@page import="com.crystaldecisions.sdk.occa.report.lib.*" %>

<%@page import="com.crystaldecisions.sdk.occa.report.data.*"%> 

<%@page import="com.crystaldecisions.report.web.viewer.*"%>

<%@page import="com.crystaldecisions.reports.sdk.*" %>

<%@page import="com.crystaldecisions.reports.reportengineinterface.*"%>

<%@page import="com.crystaldecisions.sdk.occa.report.exportoptions.*" %>

<% //Java imports. %>

<%@page import="java.io.*" %>

<%

  String reportName = "reporteFacturas.rpt";

  try {

  //check to see if the report source already exists

  Object reportSource = null; //Force to create the Report

  //if the report source has not been opened

  if (reportSource == null) {

  //---------- Create a ReportClientDocument -------------

  ReportClientDocument oReportClientDocument = new ReportClientDocument();

  //---------- Set the path to the location of the report soruce -------------

  //Open report.

  oReportClientDocument.open(reportName, 1);

  //Get the report source

  reportSource = oReportClientDocument.getReportSource();

  //session.setAttribute("reportSource", reportSource);

  //Cache report source.

  //This will be used by the viewer to display the desired report.session.setAttribute("reportSource", reportSource);

  CrystalReportViewer crv = new CrystalReportViewer();

  crv.setName("Crystal_Report_Viewer");

  crv.setReportSource(reportSource);

  //Passing parameters

  crv.setHasRefreshButton(true);

  crv.setDisplayGroupTree(false);

  crv.refresh(); //Ask for parameters

  crv.processHttpRequest(request, response,

  getServletConfig().getServletContext(), out);

  crv.dispose();

  }

  //Redirect to the viewer page.

  //response.sendRedirect("CrystalReportViewer.jsp");

  } catch (ReportSDKException e) {

  out.print(e);

  }

%>

/************* CODE **************/

Anyone could help me?

I've lost a lot of time trying to solve this.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

This absolutely worked for me. Thanks Rodney.

To add - since your essentially reinitializing a new connection info object with the same properties you can just do

IConnectionInfo originalConnection = reportClientDoc.getDatabaseController().getConnectionInfos(null).getConnectionInfo(0);

PropertyBag propertyBag = new PropertyBag();

propertyBag.putAll(originalConnection.getAttributes());

Former Member
0 Kudos

Dear Erica,

I got the same problem, may I know your solution?

Basically we need to refresh the datasource to make the report to retreieve latest data, but can't find answer for it.

Best Regards,

Rodney

Former Member
0 Kudos

Well, I´m Erick...

Unfortunately I couldn't fix the problem and I decide using other tool. Instead Crystal Reports I rather to use Tibco Jasper Reports.

It is really amazing, it's a complete ecosystem for Reporting... It has a Server and a Studio to build your reports... It was very easy to use. Of course... it's open source and free to use (Community Edition)

So... It's your choice... Loose a lot of time trying to fix the Crystal Reports or make that things happen with other tool, in this case Tibco Jaspr Reports.

Good luck!

Former Member
0 Kudos

Dear Erick,

Thanks for your advice.

I just make it happend after tens of thousands failure & depression.

Below is the code for your reference and hope you have a nice day.

🙂

<%@ page import="com.crystaldecisions.report.web.viewer.CrystalReportViewer,
                 java.io.ByteArrayInputStream,
                 java.sql.Connection,
                 java.sql.DriverManager,
                 java.sql.ResultSet,
                 java.sql.Statement,
                 com.crystaldecisions.sdk.occa.report.data.*,
                 com.crystaldecisions.sdk.occa.report.application.DatabaseController,
                 com.crystaldecisions.sdk.occa.report.application.DBOptions,
                 com.crystaldecisions.sdk.occa.report.application.OpenReportOptions,
                 com.crystaldecisions.sdk.occa.report.application.ReportClientDocument,                
                 com.crystaldecisions.sdk.occa.report.lib.*,
                 com.crystaldecisions.sdk.occa.report.exportoptions.*;                                
                 "
%><%
String reportPath;
ReportClientDocument reportClientDocument;
Connection connection;
Statement statement;
ResultSet resultSet;
ByteArrayInputStream byteArrayInputStream;
byte[] byteArray;
int bytesRead;

reportPath = "TEST/po.rpt";

final String LOCAL_SCHEMA_FILE = "D:\\po.xsd";
final String SERVER_TYPE       = "XML";

final String PREQESERVERNAME   = "D:\\po.xml D:\\po.xsd";
final String DATABASE_DLL      = "crdb_xml.dll";
final String PREQESERVERTYPE   = "XML";
final String SERVER_NAME       = "D:\\po.xml D:\\po.xsd";
final String LOCAL_XML_FILE    = "D:\\po.xml";

reportClientDocument = new ReportClientDocument();
reportClientDocument.open(reportPath, 0);

IConnectionInfo oldConnectionInfo = new ConnectionInfo();
IConnectionInfo newConnectionInfo = new ConnectionInfo();

DatabaseController dbController = reportClientDocument.getDatabaseController();
oldConnectionInfo = dbController.getConnectionInfos(null).getConnectionInfo(0); 

PropertyBag boPropertyBag1 = new PropertyBag();

boPropertyBag1.put("Database DLL",      DATABASE_DLL);   
boPropertyBag1.put("PreQEServerName",   PREQESERVERNAME);
boPropertyBag1.put("PreQEServerType",   PREQESERVERTYPE);
boPropertyBag1.put("Server Type",       SERVER_TYPE);
boPropertyBag1.put("Server Name",       SERVER_NAME);
boPropertyBag1.put("Local XML File",    LOCAL_XML_FILE);
boPropertyBag1.put("Local Schema File", LOCAL_SCHEMA_FILE);

newConnectionInfo.setAttributes(boPropertyBag1);

int replaceParams = DBOptions._ignoreCurrentTableQualifiers + DBOptions._doNotVerifyDB;

dbController.replaceConnection(oldConnectionInfo, newConnectionInfo, null, replaceParams);
session.setAttribute("reportSource", reportClientDocument.getReportSource());

byteArrayInputStream = (ByteArrayInputStream) reportClientDocument
        .getPrintOutputController().export(ReportExportFormat.PDF);

response.reset();

response.setHeader("Content-disposition", "inline;filename=crreport.pdf");
response.setContentType("application/pdf");

byteArray = new byte[1024];
while((bytesRead = byteArrayInputStream.read(byteArray)) != -1) {
response.getOutputStream().write(byteArray, 0, bytesRead);
}

response.getOutputStream().flush();
response.getOutputStream().close();

reportClientDocument.close();
%>